I have 2 tables:
tab1 (value has comma separated ids from tab2):
id1 val1
-----------
1 1
2 1,2
3 1,3
tab2:
id2 val2
-----------
1 a
2 b
3 c
I want to list values from Tab1 and replace comma separated val1 with val2
I made something like this:
SELECT *, (SELECT GROUP_CONCAT(val2) FROM tab2 WHERE id2 IN val1 ) from tab1
but it generates syntax error near 'val1 ) from tab1
When I remove Where Clause it works perfect:
SELECT *, (SELECT GROUP_CONCAT(val2) FROM tab2) from tab1
and it produces:
id1 val1 (SELECT GROUP_CONCAT(val2) FROM tab2 )
1 1,2 a,b,c
2 1,3 a,b,c
but I want to have in 3rd row letters that corresponds with Val1 numbers (only a,b and a,c). The Key is to replace numbers in Tab1.val1: 1,2... with letters from tab2.val2. It should produce:
id1 val1 (SELECT GROUP_CONCAT(val2) FROM tab2 WHERE id2 IN val1)
1 1,2 a,b
2 1,3 a,c
Something is happening when I add where clause but I cannot find what is my mistake.
Maybe some other idea to replace this comma separated numbers with letter values from other table?