in和exists的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jjkang_/article/details/85340900

in和exists的区别

in和exists的区别

in适合A表比B表大的情况,in会做全表扫描,最坏情况下要扫描 A*B次

select * from A where id in (select id from B)

exists适合A表比B表小的情况,exists不会遍历表,只需要查询一次

select * from A where exists(select 1 from B where a.id = b.id)

猜你喜欢

转载自blog.csdn.net/jjkang_/article/details/85340900