SQL subiendo recursivamente en un árbol


Ejemplo

WITH RECURSIVE ManagersOfJonathon AS (
    -- start with this row
    SELECT *
    FROM Employees
    WHERE ID = 4

    UNION ALL

    -- get manager(s) of all previously selected rows
    SELECT Employees.*
    FROM Employees
    JOIN ManagersOfJonathon
        ON Employees.ID = ManagersOfJonathon.ManagerID
)
SELECT * FROM ManagersOfJonathon;
Carné de identidad FName LName Número de teléfono ManagerId DepartmentId
4 Johnathon Herrero 1212121212 2 1
2 Juan Johnson 2468101214 1 1
1 James Herrero 1234567890 NULO 1