发布网友
共2个回答
热心网友
in 是把外表和内表作hash 连接;
exists 是对外表作loop循环,每次loop循环再对内表进行查询。
一直以来认为exists比in效率高的说法是不准确的。
如果查询的两个表大小相当,那么用in和exists差别不大。
如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in。
希望对你有帮助。
热心网友
从语义上这俩扯不上关系:
exists判断子查询有无返回
in判断某值是否存在于集合里面
但是有点经验的码农发现这俩在很多场合可以互换:
select * from a where exists (select 1 from b where col = value)
select * from a where value in (select col from b)