SQL récursivement monter dans un arbre


Exemple

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;
Id FName LName Numéro de téléphone ManagerId DépartementId
4 Johnathon Forgeron 1212121212 2 1
2 John Johnson 2468101214 1 1
1 James Forgeron 1234567890 NUL 1