Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Parkaw
Starting Member
16 Posts |
Posted - 2006-09-05 : 13:13:43
|
So I have a categorization table, looks a little something like this:ID Parent_Id Child_ID1 1 33 1 5etc.and I am looking for a way to select every thing from one parent id, all of its children, all of their children, and their children's children, etc.Is there any easy way to do this? |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-09-05 : 13:16:30
|
check out "trees and hierarchies" search.typically there is only an ID and ParentID. Having a childID column limits a parent to only having one child not to mention opens the possibility to conflicting values.Be One with the OptimizerTG |
 |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-09-05 : 13:20:07
|
quote: Originally posted by TG check out "trees and hierarchies" search.typically there is only an ID and ParentID. Having a childID column limits a parent to only having one child not to mention opens the possibility to conflicting values.Be One with the OptimizerTG
EDIT: (here's the link to the comments and the original article)http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=15499Be One with the OptimizerTG |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
Parkaw
Starting Member
16 Posts |
Posted - 2006-09-06 : 13:10:14
|
So its going to look something like this: SELECT toptier.parent_item_category_uid, midtier.parent_item_category_uid AS Expr1, midtier.parent_item_category_uid AS Expr2FROM item_category_hierarchy INNER JOIN item_category_hierarchy midtier ON item_category_hierarchy.parent_item_category_uid = midtier.item_category_hierarchy_uid INNER JOIN item_category_hierarchy toptier ON midtier.parent_item_category_uid = toptier.item_category_hierarchy_uidwhere toptier.item_category_hierarchy_uid = 3132? |
 |
|
|
|
|