我有两张这样的桌子
Table 1
id name
1 ABC
2 DEF
3 GEF
Table 2
name meal
ABC m1
ABC m2
GEF m1
Table 3
meal detail
m1 mutton
m2 beaf
我怎样才能得到这样的输出?
Id name meal_detail
1 ABC mutton,beaf
2 DEF
3 GEF mutton
提前谢谢
最佳答案
SELECT t1.id,
t1.`name`,
GROUP_CONCAT(t3.detail) AS `meal_detail`
FROM t1
LEFT JOIN t2 ON t2.`name` = t1.`name`
LEFT JOIN t3 ON t3.meal = t2.meal
GROUP BY t1.`name`
关于mysql - mysql连接查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4029030/