Oracle concatenation of columns with comma

concatenation, database, oracle, sql, string-aggregation

Solution

You will want to use `LISTAGG()` to perform this task. The other answers don't remove any of the duplicate values, to remove the duplicates, you can use something similar to this:

select c.efforts_id, 
  c.cycle_name,
  listagg(r.release_name, ', ') within group (order by c.efforts_id) as release_name
from
(
  select efforts_id,
    listagg(cycle_name, ', ') within group (order by efforts_id) as cycle_name
  from yourtable
  group by efforts_id
) c
inner join
(
  select distinct efforts_id, release_name
  from yourtable
) r
  on c.efforts_id = r.efforts_id
group by c.efforts_id, c.cycle_name

See SQL Fiddle with Demo

Problem

Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle? Could some one please tell me how to achieve the following? Table: ``` efforts_id cycle_name release_name 123 quarter march 123 half april 123 full april 124 quarter may ``` My expected output: ``` efforts_id cycle_name release_name 123 quarter,half,full march,april 124 quarter may ``` I am a beginner in oracle so not sure how to do this. Any help would be appreciated. Thanks

Original source

Related problems