Last active
April 5, 2022 23:08
-
-
Save rsaryev/38ef0192a94bc37462f4778ab5ac5723 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 tree AS (SELECT *, id AS root_category | |
FROM categories | |
WHERE parentId IS NULL | |
UNION ALL | |
SELECT c.*, p.root_category | |
FROM categories c | |
JOIN tree p | |
ON c.parentId = p.id) | |
SELECT * | |
FROM tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment