由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to query a tree
相关主题
问个SQL的问题mysql索引/优化的一个问题
问个问题请教一个SQL Query
SQL问题请教SQL server 2000有hidden records吗?
问一个query,about Recursive Queries Using Common Table Expressions誰來幫我開來開悄? Interesting SQL query
[转载] Can anyone interpret this simple SQL?请教2个sql query 问题
oracle和XMLMerge table with one single query?
pls help me in this Sql query求教:怎么在select 出的结果里加一行
ask for help with a simple query!!!a problem, thank you
相关话题的讨论汇总
话题: tree话题: xx话题: parentid话题: query话题: select
进入Database版参与讨论
1 (共1页)
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

1 (共1页)
进入Database版参与讨论
相关主题
a problem, thank you[转载] Can anyone interpret this simple SQL?
怎么求和oracle和XML
问个基本的select问题pls help me in this Sql query
union function differenct between sql server 2005 and 2008?ask for help with a simple query!!!
问个SQL的问题mysql索引/优化的一个问题
问个问题请教一个SQL Query
SQL问题请教SQL server 2000有hidden records吗?
问一个query,about Recursive Queries Using Common Table Expressions誰來幫我開來開悄? Interesting SQL query
相关话题的讨论汇总
话题: tree话题: xx话题: parentid话题: query话题: select