最佳答案
基本上,有一个属性表和转换表——一个属性有多个转换。
我需要为指定语言中的每个属性从翻译中选择 id 和值,即使该语言中没有翻译记录。要么是我遗漏了某种连接技术,要么是连接(不涉及语言表)在这里不起作用,因为下面的代码没有返回具有指定语言中不存在的翻译的属性。
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个表似乎比子查询的性能更差)。