How to get list of values in GROUP_BY clause?

Jagmal picture Jagmal · Jan 29, 2009 · Viewed 40.5k times · Source

If I have data like this in a table

id   data
--   ----
1    1
1    2
1    3
2    4
2    5
3    6
3    4

How do I get results like this in a query (on sybase server)?

id   data
--   ----
1    1, 2, 3
2    4, 5
3    6, 4

Answer

lpfavreau picture lpfavreau · Jan 30, 2009

I know that in MySQL there is GROUP_CONCAT and in Sybase I think it's LIST as stated in another answer:

SELECT id, LIST(data||', ')
FROM yourtable
GROUP BY id