今天同事发以下两个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
前面是画蛇添足了,呵呵