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 array
  • unnest() turns array separate rows - 1 each element
  • distinct removes duplicate rows
  • array_agg() joins rows single csv string (typically group by clause, no need here there's 1 group)

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -