0

I am trying to create a query that returns a single row for each unique ID in my oracle table. The problem is that i have one column, Description, that isnt unique in each row (Description-column is the only coulmn that can differ for each ID row btw). This is what my table looks like:

ID              Description       Customer         
==================================================
5119450733      Cost              GOW_1
5119450733      Price             GOW_1
1543512377      Cost              GOW_2

Is there a way to query the table so that i append the results from Description so that i can have unique id rows? for example like this:

ID              Description       Customer         
==================================================
5119450733      Cost,Price        GOW_1
1543512377      Cost              GOW_2
user1096112
  • 107
  • 2
  • 7

1 Answers1

1

Use LISTAGG function if you are using Oracle 11g Release 2.

SELECT Id, 
       listagg(Description,',') WITHIN GROUP(ORDER BY description) AS Description, 
       Customer 
FROM   <table_name>
GROUP BY id, customer;

Refer the below link to know more about String Aggregation Techniques on different versions.

Dba
  • 6,511
  • 1
  • 24
  • 33