Remove Redundant Values in Cell built from LISTAGG, Oracle SQL -


this question has answer here:

i'm new querying in oracle. have built oracle query using listagg so:

select a.field1,  listagg(d.field2, ';') within group (order d.field2) field_alias table1 a,  table2 b,  table4 c, table5 d  a.field2 = b.field2 , b.field2 = c.field2 , c.field3 = d.field3  group a.field1 

which returns:

field1   field2 ---------------- 504482   labour;labour;labour;labour;labour;labour;labour;labour 

what simplify second field , remove redundant values get:

field1   field2 ---------------- 504482   labour 

is possible?

i don't think listagg() takes distinct keyword. 1 approach use subquery:

select field1, listagg(d.field2, ';') within group (order field2) (select distinct a.field1, d.field2       table1 join            table2 b            on a.field2 = b.field2 join            table4 c            on b.field2 = c.field2 join            table5 d            on c.field3 = d.field3       ) t group field1 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -