Created
October 24, 2023 12:34
-
-
Save sowich/7e2f580611f20db09fd274fbde077848 to your computer and use it in GitHub Desktop.
parent_id_tree.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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