SQL查询-存在一个表而不在另一个表中的数据

(64条消息) SQL查询-存在一个表而不在另一个表中的数据_请加油吧的博客-CSDN博客

 

SQL查询-存在一个表而不在另一个表中的数据

方法1:使用not in 容易理解,效率低,执行时间为1.395s

select distinct a.id from a where a.id not in (select id from b)

 

方法2:使用left join on…where b.id is null 执行时间:0.739s

select a.id from a left join b on a.id = b.id where b.id is null

方法3:逻辑相对复杂,但是速度最快,执行时间:0.570s

select * from b where (select count(1) as num from a where a.id = b.id) = 0

 

posted @ 2022-10-20 10:09  白云~  阅读(642)  评论(0编辑  收藏  举报