I need to extract some data from my DB2 database. I have keywords in one table and each keyword is a separate row. In the extract I want to have all keywords for all IDs in one string separated by a comma.
So, to explain: I have such data
ID | keyword
===========================
prd1 | test
---------------------------
prd2 | keywords
---------------------------
prd1 | flower
---------------------------
prd4 | picture
---------------------------
prd7 | 234567
---------------------------
prd9 | reored
---------------------------
prd4 | finland
---------------------------
prd0 | 983y23
---------------------------
prd4 | code
---------------------------
prd9 | tratata
And here is a sample of what I want to achieve:
ID | keyword concatenated
===========================
prd1 | test, flower
---------------------------
prd2 | keywords
---------------------------
prd4 | picture, finland, code
---------------------------
prd7 | 234567
---------------------------
prd9 | reored, tratata
---------------------------
prd0 | 983y23
---------------------------
I tried with concat
:
SELECT concat(keyword) FROM table.keywordTbl
I tried with some DB2 specific commands:
SELECT IDs, Sys_Connect_By_Path(varchar(keyword), ', ') AS "keyword concatenated" FROM table.keywordTbl START WITH ID='prd1' CONNECT BY ID=keyword
PIVOT
is not right for this, but I have checked it too.
GROUP_CONCAT
is not working either.
Of course, none of these work...
Do you have any hints for me?