sql - Single text value which get unique value from all rows -
assume have these rows:
row 1 apple,watermelon,pineapple
row 2 apple,pineapple,orange
row 3 apple,blue berry
i want create single text value unique value rows.
how query?
expected result:
apple,watermelon,pineapple,orange,blue berry
try this:
select array_agg(val) ( select distinct unnest(string_to_array(my_column, ',')) val my_table) x a breakdown of what's going on:
string_to_array()splits string, using specified delimiter, true arrayunnest()turns array separate rows - 1 each elementdistinctremoves duplicate rowsarray_agg()joins rows single csv string (typicallygroup byclause, no need here there's 1 group)
Comments
Post a Comment