Godnyl Pula
Godnyl Pula

Reputation: 125

Multiple row data in single row as comma separated (Oracle)

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 

Upvotes: 0

Views: 2069

Answers (1)

EJ Egyed
EJ Egyed

Reputation: 6094

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

Upvotes: 2

Related Questions