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