Consider the following table:
| ID | ParentID |
|---|---|
| 1 | null |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
I want the result as such:
1: [2,3,4]
2: [3,4]
3: [4]
4: null
(i.e) Since 1 is the parent of 2 which is the parent of 3 and so on...
I tried this query but it requires a value:
WITH RECURSIVE a AS (
SELECT 1 AS id # I need to get all values instead of a specific value
UNION ALL
SELECT b."ID"
FROM "tblName" "b" JOIN "c" ON "c"."id" = "b"."ParentID"
)
SELECT * FROM c