该汇总来自于[日]MICK的《SQL基础教程》与《SQL进阶教程》,这两本书内容深入浅出,非常值得学习。
例子:找出员工表emp中拥有技能表skills中全部技能的员工id
(例子与解题思路来自于[日]MICK的《SQL基础教程》)
select distinct id from emps a
where not exists
(select skill from skills b
where not exists (select skill from emps c where c.id=a.id and c.skill= b.skill))
Oracle、SQL Server等数据库可以使用except
以上SQL语句可以改为
select distinct id
from emps a
where not exists<