user3380194 user3380194 - 6 months ago 11
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
select   col1, listagg(col2, ',') within group (order by col2) as new_col_name
from     table_name
group by col1;