ITPub博客

首页 > Linux操作系统 > Linux操作系统 > exists 的问题

exists 的问题

原创 Linux操作系统 作者:paulyibinyi 时间:2008-01-08 17:22:34 0 删除 编辑

今天同事发以下两个sql来问我,怎么运行结果一样

Select Id
      From Tb_Admin_Role
      Where Exists (Select Id From Tb_Admin_Role Connect By Prior Id = Parent_Id Start With Id = 222);
           
Select Id
      From Tb_Admin_Role
      Where Exists (Select Id From Tb_Admin_Role Connect By Prior Id = Parent_Id Start With Id = 1);

 

一看,写法有问题

这样写才是对的,两表之间ID必须关联

 

Select Id
      From Tb_Admin_Role a
      Where Exists (Select Id From Tb_Admin_Role b  where a.id=b.id   Connect By Prior Id = Parent_Id Start With Id = 222);
           
Select Id
      From Tb_Admin_Role a
      Where Exists (Select Id From Tb_Admin_Role  b where a.id=b.id Connect By Prior Id = Parent_Id Start With Id = 1);

其实上面这个

Select Id
      From Tb_Admin_Role a
      Where Exists (Select Id From Tb_Admin_Role b  where a.id=b.id   Connect By Prior Id = Parent_Id Start With Id = 222);
           

就等价于

Select Id From Tb_Admin_Role  Connect By Prior Id = Parent_Id Start With Id = 222

前面是画蛇添足了,呵呵

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7199859/viewspace-119560/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
学习数据库

注册时间:2007-12-11

  • 博文量
    902
  • 访问量
    6576903