基本上有属性表和翻译表-一个属性有很多翻译。
我需要从翻译中为指定属性的每个属性选择id和value,即使没有该语言的翻译记录也是如此。 我缺少某种连接技术,或者连接(不涉及语言表)在这里不起作用,因为以下操作不会以指定语言返回不存在的翻译属性。
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
所以问题部分。有没有一种方法可以从单个子查询中获取多个列,或者我应该使用两个子查询(mysql足够聪明来对它们进行分组?)还是要加入以下方法:
[[归因于语言]到翻译](连接3个表似乎比子查询的性能差)。