sql中in和exists區別


1.exist,not exist一般都是與子查詢一起使用. In可以與子查詢一起使用,也可以直接in (a,b.....)

2.exist會針對子查詢的表使用索引. not exist會對主子查詢都會使用索引. in與子查詢一起使用的時候,只能針對主查詢使用索引. not in則不會使用任何索引. 注意,一直以來認為exists比in效率高的說法是不准確的。

區別:

1.性能的考慮此時就按子表大主表小用exist,子表小主表大用in的原則就可以.
2.寫法的不同, exist的where條件是: "...... where exist (..... where a.id=b.id)"
  in的where條件是: " ...... where id in ( select id .... where a.id=b.id)"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM