场景:假设有A
、B
两表, id
为关联键
方法一
最好理解的方法1
select * from A where A.id not in (select B.id from B)
方法二
最常用的方法1
select * from A left join B on A.id = B.id where B.id is null
方法三
最快的方法1
select * from B where (select count(1) from A where A.id = B.id ) = 0