Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Concatenate columns and remove duplicates

user7675104Mar 26 2014 — edited Mar 31 2014

I have a table which contains comma delimited values in a few columns. I would like to concatenate the comma delimited values and remove duplicates.  I'm using the code below to concatenate the values but It does not remove the duplicates. I've included a sample of the columns and what I'm trying to achieve. I'm using Oracle 11. Can anyone help?

Existing Table:

id   codes

1    A,BD,ED,F

1    L,ND,ST,ED,F

2    DC,S

2    A,BD

2    DC,S

Expected output:

id   codes

1    A,BD,ED,F,L,ND,ST

2    DC,S,A,BD

Output being returned:

id    codes

1     A,BD,ED,F,L,ND,ST,ED,F

2     DC,S,A,BD,DC,S

Using the code below to concatenate but its not removing the duplicate values.

Select id,

LISTAGG(codes,',') WITHIN GROUP (Order by codes) as codes

FROM (

Select unique

id, codes

From codetable

)

group by id

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2014
Added on Mar 26 2014
14 comments
7,425 views