我有两个表,ingredient
和ingredient_language
。
我需要显示(来自SQL)每种成分的所有翻译,如果我没有任何某种语言的翻译,行必须像这样显示,例如:
Language | Ingredient
ENG Salt
GER NULL
如何显示?
表的结构是
Ingredient{id_ingredient}
Ingredient_Language{id_ingredient, id_language, traduction}
感谢。
修改
SELECT i.id_ingredient, l.id_language, l.trad
FROM Ingredient i
LEFT OUTER JOIN Ingredient_language l ON l.id_ingredient = i.id_ingredient
Okey,结构是:
·Table 1 (Ingredient) > Columns: Id_ingredient (PK), standard_name
·Table 2 (Language) > Columns: ID_Language (PK), name_language
·Table 3 (Ingredient_Language) > Columns: ID_Ingredient_Language (PK),ID_ingredient (FK), ID_LANGUAGE(FK), description
数据示例(此时无法执行任何屏幕):
·Table 1: 01, Orange
·Table 2: SP, SPANISH
ENG, ENGLISH
·Table 3: 01, 01, SP, Naranja
我需要得到什么?以下示例:
Header: id_language, id_ingredient, description
Row1: SP 01 NARANJA
Row2: ENG 01 NULL
感谢您的帮助。
答案 0 :(得分:1)
SELECT l.traduction,l.id_language,i.id_ingredient
FROM Ingredient_Language AS l
LEFT OUTER JOIN Ingredient AS i ON l.id_ingredient = i.id_ingredient
只需根据需要更改SELECT部分。
只是一个猜测,你可能真的想从你的语言表开始加入,如
SELECT l.id_language,i.id_ingredient
FROM Language l
LEFT OUTER JOIN Ingredient_Language il ON l.id_language = il.id_language
LEFT OUTER JOIN Ingredient i ON li.id_ingredient = i.id_ingredient
答案 1 :(得分:0)
您希望从交叉联接开始,它将每种成分与每种语言结合起来:
someProp
并使用
添加所有现有翻译SELECT i.id_ingredient, l.id_language, il.trad
FROM Ingredient i
CROSS JOIN Language l
如果您的数据库不支持LEFT JOIN Ingredient_language il
ON il.id_ingredient = i.id_ingredient
AND il.id_language = l.id_language
,您可以尝试
CROSS JOIN