SQL concatenate rows into one field (DB2)

You can also use LISTAGG() function, if you have DB2 v9.7+. The first parameter is the column, the second is separator.

SELECT 
  ID
, LISTAGG(keyword, ',') AS "keyword concatenated"
    FROM table.keywordTbl 
GROUP BY ID

Try to modify query accordingly to the below script

 SELECT 
    ID, 
    SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',keyword))) as VARCHAR(1024)), 3) AS "keyword concatenated"
    FROM table.keywordTbl 
    GROUP BY ID

Tags:

Sql

Db2

Concat