You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WITH RECURSIVE generation AS (
SELECT
id,
first_name,
city,
parent_id,
0AS generation_number
FROM parent_child
WHERE parent_id IS NULLUNION ALLSELECTchild.id,
child.first_name,
child.city,
child.parent_id,
generation_number +1AS generation_number
FROM parent_child child
JOIN generation g ONg.id=child.parent_id
)
SELECT*FROM generation
ORDER BY generation;
Get some specific generation
WITH RECURSIVE generation AS (
SELECT
id,
first_name,
city,
parent_id,
0AS generation_number
FROM parent_child
WHERE parent_id IS NULLUNION ALLSELECTchild.id,
child.first_name,
child.city,
child.parent_id,
generation_number +1AS generation_number
FROM parent_child child
JOIN generation g ONg.id=child.parent_id
)
SELECT*FROM generation
WHERE city ='texas'AND generation_number =1ORDER BY generation_number;