I have two tables as follows. (Table A and Table B). Table B has a field that contains multiple IDs from table A but comma separated. They are guaranteed to exists in Table A.
Table A
FIELD1 FIELD2
1 CAR
2 BUS
3 TRUCK
.
.
Table B FIELD2 : "1,3".
What I want is for each record in B (From filter condition)
FIELD1 FIELD2 FIELD3
B.ID CAR,TRUCK something....
I want to pull FIELD2 from table A where IDs are matched for each field in Table B (FIELD2). What's the best way I could achieve this?
This is what I tried, but it does not give what I want.
SELECT
GROUP_CONCAT(A.FIELD2) AS VEHICALS
FROM B
LEFT JOIN A ON A.FIELD1 IN (B.FIELD2)
WHERE B.FIELD_X > 20;
Any help is appreciated.