Reputation: 1011
I have 2 tables like this
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
How can I get output like this?
Id name meal_detail
1 ABC mutton,beaf
2 DEF
3 GEF mutton
Thanks in Advance
Upvotes: 1
Views: 91
Reputation: 255115
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`
Upvotes: 3