我有 2 个表:
interests (storing the interest ID and name)
person_interests(storing the person_id and interest_id)
我如何选择特定人未选择的所有兴趣?
我已经尝试了以下 SQL 查询,但仍然没有得到想要的结果
SELECT *
FROM interests LEFT JOIN person_interests
ON interests.id=person_interests.person_id
WHERE person_interests.id IS NULL
AND person_id=66;
最佳答案
使用NOT EXISTS
SELECT *
FROM interests
WHERE NOT EXISTS (
SELECT person_interests.interest_id
FROM person_interests
WHERE person_id = 66
AND interests.id = person_interests.interest_id
)
关于sql - 与 UNION SQL 查询相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28287879/