Assuming you want to get siblings @p0 values, you can use a simple self-join:
SELECT p.Child FROM Table1 c INNER JOIN Table1 p ON c.Parent = p.Parent WHERE c.Child = @p0 AND p.Child <> @p0
The offer does not equally guarantee that you will get siblings, not including the value you were looking for. Remove it as needed.
SQL script example
Since you mention recursion, perhaps you need the whole tree to start with the parent of the value @p0 . In this case, you can use a recursive CTE:
WITH parent AS ( SELECT Parent FROM Table1 WHERE Child = @p0 ), tree AS ( SELECT x.Parent, x.Child FROM Table1 x INNER JOIN parent ON x.Parent = parent.Parent UNION ALL SELECT y.Parent, y.Child FROM Table1 y INNER JOIN tree t ON y.Parent = t.Child ) SELECT Parent, Child FROM tree
Sample SQL script using your data and with additional data to demonstrate a recursive CTE
lc.
source share