postgresql : sql to select all distinct characters from column data

select * from company:

 id | market | symbol | crawl_date
----+--------+---------+------------
  1 | ss         | dd       | 2014-10-21
  2 | ss         | ss        | 2014-10-21
  3 | ss1       | ds        | 2014-10-21
  4 | ss1       | sd1      | 2014-10-21
  5 | ss1       | dd1     | 2014-10-21
  6 | ss1       | ss1      | 2014-10-22
  7 | ss1       | d11     | 2014-10-22

Get all distinct characters in column company.symbol:



  1. select string_agg(c,'')
  2. from (
  3. select distinct regexp_split_to_table(symbol,'') as c
  4. from company
  5. ) t;

Output:

 string_agg 
------------
 1ds
(1 row)

No comments:

Post a Comment