44

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.

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
dusoft
  • 11,289
  • 5
  • 38
  • 44

1 Answers1

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

See GROUP_CONCAT.

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189