#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    PL/SQL hierarchical query


    Hey guys, I'm not really much of a pl/sql programmer, so need some help for what's probably something pretty basic.

    I have a table that has hierarchical data within it. I need to select this data in a specific way, showing the hierarchy. Can someone please let me know how to create a select statement of what I need?

    E.g Data in table (Key is unique)
    Lvl Key ParKey HasChild
    1 k1 0 1
    1 k2 0 0
    1 k3 0 1
    1 k4 0 1
    2 k34 k1 0
    2 k22 k1 1
    2 k24 k1 0
    2 k13 k3 0
    2 k52 k3 0
    2 k35 k3 0
    2 k13 k3 0
    2 k11 k4 0
    3 k56 k22 0
    3 k109 k22 1
    3 k67 k22 0
    4 k61 k109 0
    Etc etc....


    That’s generally the format the values would appear in the table if I just did a standard select. I want it displayed in a more hierarchical Parent – child way.
    The format I need to get out is as follows:
    Lvl Key ParKey hasCh
    1 k1 0 1
    2 k34 k1 0
    2 k22 k1 1
    3 k56 k22 0
    3 k109 k22 1
    4 k61 k109 0
    3 k67 k22 0
    2 k24 k1 0
    1 k2 0 0
    1 k3 0 1
    2 k13 k3 0
    2 k52 k3 0
    2 k35 k3 0
    2 k13 k3 0
    1 k4 0 1
    2 k11 k4 0


    Really appreciate help on this....
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    Okay, I figured it out. Was as simple as I thought it would be.
    SELECT * FROM table
    START WITH ParKey = 0
    CONNECT BY PRIOR key = Parkey;

IMN logo majestic logo threadwatch logo seochat tools logo