I have a table1
line | a | b | c | d | e | f | g | h |
---|---|---|---|---|---|---|---|---|
1 | 18 | 2 | 2 | 22 | 0 | 2 | 1 | 2 |
2 | 20 | 2 | 2 | 2 | 0 | 0 | 0 | 2 |
3 | 10 | 2 | 2 | 222 | 0 | 2 | 1 | 2 |
4 | 12 | 2 | 2 | 3 | 0 | 0 | 0 | 0 |
5 | 15 | 2 | 2 | 3 | 0 | 0 | 0 | 0 |
And a table2
line | criteria |
---|---|
1 | a,b |
2 | b,c,f,h |
3 | a,b,e,g,h |
4 | c,e |
I am using this code to see/select the unique results of concated/joined columns, like concat(c,',',d)
, concat(b,',',d,',',g)
and so on from table1
and is working perfectly:
SELECT DISTINCT(CONCAT(c,',',d))
FROM table1
But, instead of writing manually like concat(c,',',d)
, I want to refer to table2.criteria
to get columns references to be concated/joined from table1
so that i can see the entire unique results against each concated criteria
Tried this, but getting an error:
SELECT DISTINCT(SELECT criteria FROM table2)
FROM table1
ERROR: more than one row returned by a subquery used as an expression
SQL state: 21000
The expected unique result is something like this;
| criteria | result |
| ------------ | ---------- |
| a,b | 15,2 |
| a,b | 10,2 |
| a,b | 20,2 |
| a,b | 12,2 |
| a,b | 18,2 |
| b,c,f,h | 2,2,2,2 |
| b,c,f,h | 2,2,0,2 |
| b,c,f,h | 2,2,0,0 |
| a,b,e,g,h | 20,2,0,0,2 |
| a,b,e,g,h | 12,2,0,0,0 |
| a,b,e,g,h | 15,2,0,0,0 |
| a,b,e,g,h | 10,2,0,1,2 |
| a,b,e,g,h | 18,2,0,1,2 |
| c,e | 2,0 |