0

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 
  • 1
    Does this answer your question? [SQL Query to concatenate column values from multiple rows in Oracle](https://stackoverflow.com/questions/4686543/sql-query-to-concatenate-column-values-from-multiple-rows-in-oracle) – astentx Nov 13 '21 at 09:40

1 Answers1

2

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
EJ Egyed
  • 5,791
  • 1
  • 8
  • 23