比对表之间的字段不存在的记录not in与full join

来源:互联网 发布:windows端口不能telnet 编辑:程序博客网 时间:2024/05/28 16:15

查找两个表中不存在的记段

比如 select * from a where a.sumdate not in (select distinct sumdate from b)  

如果A表和B的数据量比较大,这样的查询语句效率是相当低下的

在这种情况下,尽量不要用not in,建议用left join或full join

比如:select * from a left join  (select distinct sumdate from b)  b on a.sumdate=b.sumdate where b.sumdate is null

这样执行起来效率就比较高