Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query down the tree 2

Status
Not open for further replies.

mbowles

Programmer
Aug 27, 2001
41
US
I have a table with an ID(autonumber), parent_id, name, etc... fields.
It is a one to many relationship with itself. I.E. each rows parent_id points to the ID of another row. (with one exception, the first records parent_id = -1 to designate the root of the tree).

How can I query down and interact with all children of a single parent. I.E. I have ID = 6. I want to find all rows with parent_id = 6 and all rows beneath them and so on until I run out of rows?
 
faq183-5322

-------------------------------------
A sacrifice is harder when no one knows you've made it.
 
thanks, I found all of the links provided to be very useful. I ended up using the books online version for now, as my "tree" will rarely have deeper than 5-6 levels for a year or more. It runs really well. My problem was that I am not a SQL guyu so was not aware of the term "adjacent heirarchy" Thanks a ton and a learned quite a but form all of the links.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top