查询相关记录

时间:2019-06-05 09:25:13

标签: oracle plsql

我在oracle表中有两条记录,它们与一个名为LEGAL_CLASS_PARENT_ID的字段相关。如何查询一条语句中的记录

enter image description here

select 
    id, FUND_ID, CLASS_TYPE, CURRENCY_ID, SUB_VOTING_ID,
    SUB_HOT_ISSUE_ID, REDS_FRQNCY_ID 
from 
    MGR.LEGAL_FUND_CLASS 
where 
    id = 13713

select 
    id, FUND_ID, CLASS_TYPE, CURRENCY_ID, SUB_VOTING_ID,
    SUB_HOT_ISSUE_ID, REDS_FRQNCY_ID, LEGAL_CLASS_PARENT_ID 
from 
    MGR.LEGAL_FUND_CLASS 
where 
    id = 28429

2 个答案:

答案 0 :(得分:0)

您可以连接LEGAL_CLASS_PARENT_IDid

select id,FUND_ID,CLASS_TYPE,CURRENCY_ID,SUB_VOTING_ID,SUB_HOT_ISSUE_ID,REDS_FRQNCY_ID,LEGAL_CLASS_PARENT_ID 
from MGR.LEGAL_FUND_CLASS l2
join MGR.LEGAL_FUND_CLASS l 
on l.LEGAL_CLASS_PARENT_ID = l2.id 

如果您想要特定的ID,请添加where

where id = 13713

答案 1 :(得分:0)

您可以使用分层查询来获取父子关系芯片连接的所有记录:

SELECT * 
  FROM MGR.LEGAL_FUND_CLASS
 START WITH ID = 28429
 CONNECT BY ID = PRIOR LEGAL_CLASS_PARENT_ID