1

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

1 Answer 1

3
   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`
Sign up to request clarification or add additional context in comments.

2 Comments

@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
@EarnWhileLearn: lucky me ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.