因為 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刪除。