Skip to content
Advertisement

How to select all parents of a child from a table

I am using SQL Server.

My table is called Employees.

It looks like this:

I am trying to build a query that returns all parents of the children

So the query would return the parents of Bin and Sam are

I tried this but wasn’t successful

but this can only work for 1 parent

How can I get the whole list of parents (managers)?

Advertisement

Answer

Use recursive cte

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement