开发者

Show child and parent together using CONNECT BY Sql statement

开发者 https://www.devze.com 2022-12-27 10:05 出处:网络
I have an sql statement that currently is just returning all the end parent rows for a list of child rows:

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

  SELECT DISTINCT row开发者_如何学Python
      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.


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! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消