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