mysql - Return all items in one row

Viewed 175

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|
2 Answers

Use group_concat():

select group_concat(name order by id separator ',') as name
from table;
Related