因为 not in不走索引,所以不在不得已情况下,就不要使用not in
下面使用 join 来替代not in 做查询
select ID from A where ID not in (select ID from B)
替换为
select A.ID from A left join B on A.ID=B.ID and B.ID is null
或者:
select A.ID from A left join B on A.ID=B.ID where B.ID is null
因为 not in不走索引,所以不在不得已情况下,就不要使用not in
下面使用 join 来替代not in 做查询
select ID from A where ID not in (select ID from B)
替换为
select A.ID from A left join B on A.ID=B.ID and B.ID is null
或者:
select A.ID from A left join B on A.ID=B.ID where B.ID is null
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。