1

I am unable to find DB2 query to make column values into one single value separating with comma.

Actual Table:

Table Name: Emp

Id Name
1 Test1
2 Test2
3 Test3

Expected Result:

Name
Test1,Test2,Test3

Cany some one suggest me the way to do it in DB2 or generic way in all databases ?

DB2 Version : 8.1 in windows environment

Many Thanks in advance!!!

user3914257
  • 41
  • 2
  • 7

1 Answers1

1

You don't mention what version of DB2 you are using. If you are on DB2 Linux/Unix/Windows, and are at version 9.7 or higher, then you can use the LISTAGG function:

SELECT LISTAGG(NAME, ',') FROM EMP

bhamby
  • 15,112
  • 1
  • 45
  • 66