December 22, 2010 at 7:17 am
Hi!
Im having some problem with recursive cte. I want to find all children of the parent. For example I have a table with two columns: parentId and childrenID:
pid id
1 2
1 3
1 4
2 4
2 5
3 1
3 2
4 5
as a result I want to get all children of each parent:
pid id
1 1
1 2
1 3
1 4
1 5
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 5
All my attempts were unsuccessful. I couldnt get result as I wanted. Help me pls to write a query to find all children.
December 22, 2010 at 7:24 am
Help us to help you:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Existing SSC articles that you may find helpful:
December 22, 2010 at 7:39 am
sry...given:
with cte as (
select 1 as pid, 2 as id union all
select 1,3 union all
select 1,4 union all
select 2,4 union all
select 2,5 union all
select 3,1 union all
select 3,2 union all
select 4,5
)
Did I missed somethin else? Is it enough?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply