Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Recursive JOIN (parent child relationships)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-10 : 00:49:17
terry writes "Hi!
I happened to see the question placed by Michael S.
http://www.4guysfromrolla.com/webtech/sqlguru/q120899-1.shtml
And I had hoped that it could give me the answer to a problem I have been placed with on a number of occasions. How do I find a “family tree” for a given “parent” in one SQL statement?

Here is a simple example:
ID, ParentID
1 0
2 1
3 0
4 2


In this simple example ID 1 has child (ID = 2) and that child (ID = 2) also has a child (ID = 4)

So if I want to see the family of ID 1 then the following doesn’t yield what I want which is.

1 0
2 1
4 2

SELECT ID, ParentID
FROM MyTable AS T1
JOIN MyTable AS T2
ON T1.ID = T2.ParentID
WHERE T1.ID = 1

Terry"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-06-10 : 00:49:17
Did you see this article (http://www.sqlteam.com/item.asp?ItemID=8866)?
Go to Top of Page

Lady
Starting Member

32 Posts

Posted - 2002-06-11 : 03:31:26



Edited by - Lady on 06/11/2002 03:31:56
Go to Top of Page
   

- Advertisement -