Skip to content

Instantly share code, notes, and snippets.

@sowich
Created October 24, 2023 12:34
Show Gist options
  • Save sowich/7e2f580611f20db09fd274fbde077848 to your computer and use it in GitHub Desktop.
Save sowich/7e2f580611f20db09fd274fbde077848 to your computer and use it in GitHub Desktop.
parent_id_tree.sql
WITH RECURSIVE epc (id, parent_id, anchor) as (
SELECT id, parent_id, anchor FROM table WHERE parent_id = 32
UNION ALL
SELECT pc.id, pc.parent_id, pc.anchor FROM table pc
INNER JOIN epc on pc.parent_id = epc.id
)
SELECT * FROM epc order by id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment