How can I concatenate set of results in MySQL?

36,156
SELECT GROUP_CONCAT(COLUMN_X SEPARATOR ',') FROM <<table>> GROUP BY NULL

See GROUP_CONCAT.

Share:
36,156
dusoft
Author by

dusoft

Check out my list of my projects at Ambience. I work at Basta digital digital marketing agency.

Updated on January 31, 2020

Comments

  • dusoft
    dusoft over 4 years

    I would like to join results returned in the set in MySQL with a comma as a separator string.

    For example, set returned contains:

    COLUMN_X
    john
    jerry
    maria
    joseph
    gugla
    

    I would like to receive the result as:

    COLUMN_X-concat
    john,jerry,maria,joseph,gugla
    

    is that possible? thanks.

    SELECT CONCAT(rooms.ID,",") FROM rooms AS rooms LEFT JOIN inter AS i ON rooms.ID=i.value WHERE xxx=999
    

    doesn't work as I would like it to as it returns separate results.