Recursive JOINs

suggest change

Recursive joins are often used to obtain parent-child data. In SQL, they are implemented with recursive common table expressions. WITH RECURSIVE is required by PostgreSQL and rejected by SQL Server. This example assumes People(Name, Parent):

WITH RECURSIVE MyDescendants AS (
    SELECT Name, Parent
    FROM People
    WHERE Name = 'John Doe'

    UNION ALL

    SELECT People.Name, People.Parent
    FROM People
    JOIN MyDescendants ON People.Parent = MyDescendants.Name
)
SELECT * FROM MyDescendants;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents