tags:

views:

27

answers:

1

I have an sql statement that currently is just returning all the end parent rows for a list of child rows:

  SELECT DISTINCT row
      FROM table heirarchy
      WHERE parent_row = NULL
    CONNECT BY nocycle PRIOR parent_row = row
     START WITH row IN (select statement returning child rows)

Is there a way to show the child and its corresponding parent together in the same result set using a modified version of my sql?

Thanks.

A: 

Found the answer myself haha. Anyways, the solution is to use oracle's connect_by_root function.

 SELECT DISTINCT connect_by_root(row), row
      FROM table heirarchy
      WHERE parent_row = NULL
    CONNECT BY nocycle PRIOR parent_row = row
     START WITH row IN (select statement returning child rows)

Problem solved! :)

jonasespelita