Home > Net >  Multiple row data in single row as comma separated (Oracle)
Multiple row data in single row as comma separated (Oracle)

Time:11-14

How to make select statement where result is rows combined in comma separated manner based on columns (user & group).

enter image description here

Expected result

USER | GROUP | SUB
-------------------------
3    | 102   | 1,3,2,4,61 

CodePudding user response:

This is what LISTAGG was built for

  SELECT t.USER, t.group, LISTAGG (t.sub, ',') WITHIN GROUP (ORDER BY t.pk_id)
    FROM your_table t
GROUP BY t.USER, t.GROUP
  • Related