首页 > Linux操作系统 > Linux操作系统 > exists 的问题
今天同事发以下两个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博客 ” ,链接:https://blog.itpub.net/7199859/viewspace-119560/ ,如需转载,请注明出处,否则将追究法律责任。