递归 JOIN
递归连接通常用于获取父子数据。在 SQL 中,它们使用递归公用表表达式实现 ,例如:
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;