ORACLE EXSIST 练习

exists (sql 返回结果集为真)
notexists (sql 不返回结果集为真)


如下:
表A

表B
 


表A和表B是1对多的关系 A.ID
=> B.AID

 

select a.id from A where exists (select a.id from b where a.id = b.aid);

 

select a.id from A
where  not exists (
      select a.id from  b where a.id = b.aid  
);

 

条件查询

  select *
    from A
   where exists (select a.id
            from b
           where a.id = b.aid
             and b.name != 'b3');

select a.id
  from A
 where not exists
 (select a.id from b where a.id = b.aid  and b.name != 'b3');

 三个表联合exist

母表

子表

又子表

 

查询语句

select name from C
where exists (
      select * from b where b.id = c.bid and exists (
             select * from a where a.id = b.aid
      )
);

 

 查询结果

 

 

 

 

 

 

 

posted @ 2013-01-03 19:13  王超_cc  阅读(529)  评论(0编辑  收藏  举报