SQL Recursive JOINs


Example

Recursive joins are often used to obtain parent-child data. In SQL, they are implemented with recursive common table expressions, for example:

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

    UNION ALL

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