私はこのクエリを持っています:
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
TableB からの を持つ TableA からすべてのid
s を取得していませんclass_id
。また、他のより良いクエリの提案も受け付けています。
これは私が欲しいものです:
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