I am using this code to see the unique results of concated/joined columns 'a,b'
from table1
and is working perfectly
WITH tt as (
SELECT concat(a,',',b) AS concated FROM table1 GROUP BY concated )
select concated from tt;
But, instead of writing like 'a,b'
, I want to refer to table2.joins
to get columns references to be concated/joined so that I can see together all the unique results of table1
(based on table2.joins
)
line | sets | joins |
---|---|---|
1 | 2 | a,b |
2 | 4 | a,c,f,i |
3 | 5 | a,d,o,x,y |
4 | 2 | a,e |
Tried this but getting error. The expected result looks like this (demo);
WITH tt as (
SELECT concat(string_to_array((select joins from table2), ',')) AS concated FROM table1 GROUP BY concated )
select concated from tt;
Any simple solution would be highly appreciated.
2
Answers
Is that what you are looking for :
joins
is a column oftb_reference
, so theFROM
should beFROM tb_reference
Dynamic SQL can help to solve this problem, and here you need PL/pgSQL.