基本上,有一个属性表和翻译表 - 一个属性有多个翻译。
我需要从指定语言的每个属性的翻译中选择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个表似乎比子查询性能更差)。