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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Hierarchical category selection

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_ID
1 1 3
3 1 5
etc.
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 Optimizer
TG
Go to Top of Page

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 Optimizer
TG



EDIT: (here's the link to the comments and the original article)
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=15499

Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-05 : 20:56:37
Also refer
http://www.nigelrivett.net/SQLTsql/RetrieveTreeHierarchy.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 Expr2
FROM 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_uid
where toptier.item_category_hierarchy_uid = 3132
?
Go to Top of Page
   

- Advertisement -