基本上,有一个属性表和转换表——一个属性有多个转换.
我需要为指定语言中的每个属性从翻译中 Select id和值,即使该语言中没有翻译记录.要么我缺少一些连接技术,要么join(不涉及语言表)在这里不起作用,因为以下内容不会返回指定语言中不存在翻译的属性.
select a.attribute, at.id, at.translation
from attribute a left join attributeTranslation at on a.id=at.attribute
where al.language=1;
所以我使用这样的子查询,这里的问题是使用相同的参数对同一个表进行两个子查询(感觉像是性能消耗,除非MySQL对这些子查询进行分组,我对此表示怀疑,因为它会让您执行许多类似的子查询)
select attribute,
(select id from attributeTranslation where attribute=a.id and language=1),
(select translation from attributeTranslation where attribute=a.id and language=1),
from attribute a;
我希望能够从一个查询中获取id和翻译,所以我在后面分析列并从字符串中获取id,这至少是一个子查询,但看起来仍然不正确.
select attribute,
(select concat(id,';',title)
from offerAttribute_language
where offerAttribute=a.id and _language=1
)
from offerAttribute a
所以问题部分.
[[attribute to language]to translation](连接3个表似乎比子查询的性能更差).