avatar
How to query a tree# Database - 数据库
n*w
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
avatar
q*j
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

avatar
j*i
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。