I have this query:
SELECT A.id FROM TableB B
LEFT JOIN TableA A ON
CONCAT(',',B.class_id,',') LIKE CONCAT('%,',A.class_id,',%')
WHERE A.class_id is not null
TableA
[id] | [class_id]
---------------------
One 1, 10, 16, 18
Two 14, 11
Three 19, 13, 15
Four 10
TableB
[id] | [class_id]
---------------------
ABC 1
AC 1
DE 10
DEC 19
ACD 16
BCD 18
BCO 18
I am not getting all the id
s from TableA that has the class_id
from TableB. And I am open to any other better query suggestions as well.
This is what I want:
One // class_id contains 1, 10 16 and 18 that are in `TableB` class_id
Three // class_id contains 19 which is in `TableB` class_id
Four // class_id contains 10 which is in `TableB` class_id