DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Child to Parent

  1. #1
    Join Date
    Dec 2000
    Posts
    19

    Smile

    Hi All,
    I want to get the parent records of the child recs. If I want to do the reverse ie Parent to child then I use Level,connect by and prior functions. I want to do the reverse way. Is there any way or method.

    TIA

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    The trick is to reverse the side of the PROR keyword in the CONNECT BY clause. For example, in a clasical SCOTT.EMP table, the hierarchy from KING (president) downwards to all lower level is find by:

    Code:
    SELECT level, ename name, empno, mgr
    FROM emp
    START WITH ename = 'KING'
    CONNECT BY PRIOR empno = mgr;
    Now if you want to find all the supperiors of ADAMS, you would switch the keyword PRIOR from empno to mgr:

    Code:
    SELECT level, ename name, empno, mgr
    FROM emp
    START WITH ename = 'ADAMS'
    CONNECT BY empno =  PRIOR mgr;
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width