摘要: select * from Awhere id in(select id from B)以上查询使用了in语句,in()只执行一次,它查出B表中的所有id字段并缓存起来.之后,检查A表的id是否与B表中的id相等,如果相等则将A表的记录加入结果集中,直到遍历完A表的所有记录.它的查询过程类似于以下过程List resultSet=[];Array A=(select * from A);Array B=(select id from B);for(int i=0;i<A.length;i++) { for(int j=0;j<B.length;j++) { if(A[i].id== 阅读全文
posted @ 2013-03-19 20:09 joy696163 阅读(200) 评论(0) 推荐(0) 编辑
摘要: in 和 exists区别 in 是把外表和内表作hash join,而exists是对外表作loop,每次loop再对内表进行查询。一直以来认为exists比in效率高的说法是不准确的。如果查询的两个表大小相当,那么用in和exists差别不大。如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in:例如:表A(小表),表B(大表)1:select * from A where cc in (select cc from B)效率低,用到了A表上cc列的索引;select * from A where exists(select cc from B where c 阅读全文
posted @ 2013-03-19 19:50 joy696163 阅读(268) 评论(0) 推荐(0) 编辑