1

I have a SQL query which will fetch some data. I wrote a program to copy the data into excel sheet. This is done.

There will be multiple rows for a single incident. I want to get the collated form of that data. Say Incident no:12345 and for this there exist some 10 rows. If i query this table, ill get 10 rows as output. There exist a column work_info for all the 10 rows which i'm interested to fetch.

incident_no  work_info
12345        this is incident
12345        this is workinfo

So my question is, if I query this table with incident 12345, I need a output of just 1 row. i.e.,

incident_no  work_info
12345        this is incident,this is workinfo      

I want output should be like this. 1 row with all the work_info's collated to 1 column.

I appreciate your help.

user1835935
  • 45
  • 1
  • 5

1 Answers1

0

If you are using Oracle 11+, listagg should do the trick:

SELECT LISTAGG(work_info, ', ')
         WITHIN GROUP (ORDER BY incident_no) work_infoAgg
  FROM YOURTABLE;

Source : http://docs.oracle.com/cd/E11882_01/server.112/e17118/functions089.htm#SQLRF51487

guigui42
  • 2,441
  • 8
  • 35
  • 48