2

Is there a function in mysql that would return all items in just one row?

EXAMPLE:

Table:

| id | name |
-------------
| 1  | john |
| 2  | mike |
| 3  | jane |

Query:

SELECT concat_name(name) FROM tbl_name

concat_name as the function.

Expected Result:

|       name      |
-------------------
| john, mike, jane|
simple guy
  • 633
  • 1
  • 6
  • 19

2 Answers2

4

Use group_concat():

select group_concat(name order by id separator ',') as name
from table;
Harshil Doshi
  • 3,497
  • 3
  • 14
  • 37
0

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
Harshil Doshi
  • 3,497
  • 3
  • 14
  • 37
Pramod Kharade
  • 2,005
  • 1
  • 22
  • 41