tags:

views:

17

answers:

1
+1  Q: 

mysql join query

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

+2  A: 
   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`
zerkms
+1: Thought I was going to have to format that for you :p
OMG Ponies
@OMG Ponies: nah, now I follow your formatting style everywhere ;-) Just cheated with saving correct but not formatted query to catch the first answer ;-P
zerkms
@zerkms it works ;-)
EarnWhileLearn
@EarnWhileLearn: lucky me ;-)
zerkms