How to concatenate multiple MySQL rows into one field?

Using MySQL, I can do something like

select hobbies from peoples_hobbies where person_id = 5;

and get:

shopping
fishing
coding

but instead I just want 1 row, 1 col:



shopping, fishing, coding


Answer:

select person_id, group_concat(hobbies separator ', ')
    from peoples_hobbies group by person_id;

Comments

Popular posts from this blog