当前位置: 代码迷 >> Oracle开发 >> oracle单表联系关系查询
  详细解决方案

oracle单表联系关系查询

热度:92   发布时间:2016-04-24 07:02:25.0
oracle单表关联查询
如图所示,期望结果是随便传入一个msg_id值,能将与之相关联的数据都查出来,像我做的这个数据,应该会根据16,27,28随便一个,查询这三条信息!
parent_id 关联的msg_id
Oracle 查询

------解决方案--------------------
就是层次查询嘛
select * from (
select t.*,level lv from ecm_message t 
start with t.msg_id='16'
connect by prior t.msg_id=t.parent_id
union 
select t.*,level from ecm_message t 
start with t.msg_id='16'
connect by  t.msg_id= prior t.parent_id) tt
where tt.lv<>1
  相关解决方案