user3380194 user3380194 - 2 years ago 99
SQL Question

Oracle Query to get data

Please help to how to write the Oracle query to get the result like this
"abcd 1,5,7 xyz" from below table. And I want to include COL3 also. Please help

Oracle Database table
col1 | col2 | col3
ABCD 1 xyz
EDF 3 lmn
ABCD 5 xyz
ABCD 7 xyz

Thanks in advance. :)

Answer Source
select   col1, listagg(col2, ',') within group (order by col2) as new_col_name
from     table_name
group by col1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download