n*w 发帖数: 41 | 1 In MS SQL 7, how to query a tree,
i.e. if I have a table as follows:
ID--CONTENT--PARENTID
1--'XX'--0
2--'XX'--0
3--'XX'--0
4--'YY'--0
5--'XX'--2
6--'XX'--2
7--'WW'--5
...
How to use SQL to query either the whole structure of the tree or one whole branch?
Thx | q*j 发帖数: 156 | 2 what do you mean by querying the whole structure of the tree?
【在 n*w 的大作中提到】 : In MS SQL 7, how to query a tree, : i.e. if I have a table as follows: : ID--CONTENT--PARENTID : 1--'XX'--0 : 2--'XX'--0 : 3--'XX'--0 : 4--'YY'--0 : 5--'XX'--2 : 6--'XX'--2 : 7--'WW'--5
| j****i 发帖数: 496 | 3 Your question is a little bit vague.
Let's suppose you know the height of the query tree to be 3...
Select ID From Tree
Where ParentID In
(Select ID From Tree
Where ParentID In
(Select ID From Tree
Where ParentID = root
)
)
Union
Select ID From Tree
Where ParentID In
(Select ID From Tree
Where ParentID = root
)
Union
Select ID From Tree
Where ParentID = root
Union
Select ID From Tree
Where ID = root
It may be easier to implement this if you embed SQL into some prog
【在 n*w 的大作中提到】 : In MS SQL 7, how to query a tree, : i.e. if I have a table as follows: : ID--CONTENT--PARENTID : 1--'XX'--0 : 2--'XX'--0 : 3--'XX'--0 : 4--'YY'--0 : 5--'XX'--2 : 6--'XX'--2 : 7--'WW'--5
|
|