Click to See Complete Forum and Search --> : How to get all the hierarchy above a branch?


mamachika
04-19-2006, 10:32 AM
Hello,
I have a table which represents a tree structure. The table columns are:
ID
parentID
Name

and that data looks like this:

1 0 'first category'
2 0 'second category'
3 1 'sub category 1'
4 1 'sub category 2'
5 2 'another sub category'
6 3 'sub-sub category'

etc.

when I am in a certain category, I need to retrieve the names and IDs of all the levels above the current branch of my tree, for example in order to show a bread crumbs path.

Is there a way to retrieve that data with a single query to the database?

Thank you :)

chazzy
04-19-2006, 11:24 AM
oracle allows for hierarchical query structure. i think sql server might as well. most others do not. are you using one of those two?

mamachika
04-19-2006, 11:26 AM
I'm sorry, I should have mentuned it myself - I am using SQL server.

chazzy
04-19-2006, 01:15 PM
this should help http://www.yafla.com/papers/sqlhierarchies/sqlhierarchies.htm

mamachika
04-24-2006, 11:12 AM
Thanks!