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

Thread: tree structure

  1. #1
    Join Date
    Jun 2001
    Posts
    316
    Hi guys,
    Can ne1 pls tell me how to go about a table having data in a tree structure.

    eg:

    i have

    id parent name
    1 0 a1
    2 0 a2
    3 1 a3
    4 3 a4
    5 2 a5

    I need all the children of id 1 and all its sub and sub sub children
    eg when i query for id 1 .i shoudl get

    id parent name
    1 0 a1
    3 1 a3
    4 3 a4

    Thanx in advance for help
    sam

  2. #2
    Join Date
    Nov 2001
    Location
    Chennai
    Posts
    22
    Well, only a well written stored procedure can take care of your requirement, I guess....

    Coz, the kind of info you are storing ( tree structure in cyclic relations ), a recursive search is to be performed, the number of which is limited, if it is to be performed using subqueries or the likes.

    On the other hand, a SP will certainly be able to churn you out the results....



  3. #3
    Join Date
    Jun 2001
    Posts
    316
    gee got it!!!!

    select id,parent,name from table
    connect by id = parent start with id=1
    a beautiful funda!!!!

    more of this here

    http://www.arsdigita.com/books/sql/trees.html

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