ITeye博客

exists,in,not exists,not in

oyprunner · 2010-02-25 13:21 · sql · 数据库 · Markdown

**1 exists && in **

  --EXISTS的执行流程        
  select * from t1 where exists ( select null from t2 where y = x 
  --可以理解为:
    for x in ( select * from t1 )
     loop
        if ( exists ( select null from t2 where y = x.x )
        then 
           OUTPUT THE RECORD
        end if
     end loop
**1.2  in**

--IN的执行流程 select * from T1 where x in ( select y from T2 ) --可以理解为: select * from t1, ( select distinct y from t2 ) t2 where t1.x = t2.y; 2 not in && not exists 2.1 not in 1,例子:从A表中查出来一个集合,从B表中查出来一个集合,且A表中包含了B表中的集合,求A表中不包含B表的集合

select a.iid from A a where a.iid not in(select iid from B)  
**2.2 not exists**

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。