Created
July 30, 2019 09:32
-
-
Save szymonk92/b5f0d2e179528c81497e77e99857c946 to your computer and use it in GitHub Desktop.
Get all ancestors
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 ancestors(id, name) AS ( | |
SELECT entity.id, entity.name | |
FROM t_directory as entity | |
WHERE entity.parentDirectory = '201' | |
UNION ALL | |
SELECT next.id, next.name | |
FROM t_directory as next, ancestors | |
WHERE next.parentDirectory = ancestors.id | |
) | |
SELECT * FROM ancestors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment