Similar to this question:
How to execute a query for all nodes between two nodes in a tree?
But I do not have a closing (flattened) table, a child can have many parents, and ID traversal is not necessarily in order. There is no limit to the depth of nesting.
Suppose a circular reference is not possible ... I would like to return all the rows needed to go through the hierarchy.
Suppose the following table:
ParentID ID RowNumber(Reference)
1 2 1
2 4 2
4 3 3
3 5 4
1 6 5
6 7 6
2 8 7
3 9 8
1 8 9
6 8 10
Given 1how can I write one query to return all rows (get the relationships of all descendants)?
Similarly, given 2I would expect lines 2,3,4,7,8
Given 6, I would expect lines 6 and 10
, . .
MSAccess SQL Server 2000 +