I have seen similar but not Exactly the same requests.
If I had the following table
Parent Child
1 2
1 3
4 3
5 1
6 1
5 7
8 9
I selected "1" I would expect back all records where one is the parent or child but also all related parents and children for instance row "5 , 7" because 5 is the parent of "1"
so the result set for 1 would be
Parent Child
1 2
1 3
4 3
5 1
6 1
5 7
So it would NOT include the row
Parent Child
8 9
This is as close as I can get so far
;WITH LinksDown AS (
SELECT *
FROM RecursiveTable
WHERE Parent = 1
UNION ALL
SELECT rt.*
FROM RecursiveTable rt
JOIN LinksDown ld on ld.Child = rt.Parent
),
LinksUp AS (
SELECT *
FROM RecursiveTable
WHERE Child = 1
UNION ALL
SELECT rt.*
FROM RecursiveTable rt
JOIN LinksUp lu on lu.Child = rt.Parent
)
select distinct *
from LinksDown
Union All
select distinct * from LinksUp
But this has the following output which is far from whats needed
Parent Child
1 2
1 3
1 2
1 3
5 1
6 1