我有这个查询:
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
表A
[id] | [class_id]
---------------------
One 1, 10, 16, 18
Two 14, 11
Three 19, 13, 15
Four 10
表B
[id] | [class_id]
---------------------
ABC 1
AC 1
DE 10
DEC 19
ACD 16
BCD 18
BCO 18
我没有id
从 TableA 中获得所有class_id
来自 TableB 的 s。我也愿意接受任何其他更好的查询建议。
这就是我要的:
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