MySQL : Multiple row as comma separated single row

后端 未结 1 610
感情败类
感情败类 2020-11-28 08:01

I have two tables : DISH and DISH_HAS_DISHES. Dish table has all the dishes and \"Dish_has_dishes\" table has a one-to-many relationship with \"Dish\" table. I.e. a dish can

相关标签:
1条回答
  • 2020-11-28 08:29

    Use GROUP_CONCAT FUNCTION

    http://dev.mysql.com/tech-resources/articles/4.1/grab-bag.html

     SELEct m.meal_Id, 
            GROUP_CONCAT(dish_id) dish_ids, 
            GROUP_CONCAT(dish_name) dish_names
     FROM DISH_HAS_DISHES m JOIN DISH d ON (m.dish_id = d.dish_id)
     GROUP BY meal_Id
    
    0 讨论(0)
提交回复
热议问题