Regarding company tree in PostgreSQL
I am using the following to get the subsidiaries of the company with id = 11.
SELECT * FROM "OwnershipTable"
WHERE "Parent_ID" = 11;
giving me the following output
Company_ID | Company_Name | Parent_ID | Parent_Name |
---|---|---|---|
111 | Holdco 1 | 11 | Topco |
112 | Holdco 2 | 11 | Topco |
113 | Holdco 3 | 11 | Topco |
114 | Holdco 4 | 11 | Topco |
However, I would like to investigate if any of the Holdco-companies has any subsidiaries. My question is therefore: Is it possible insert the column "Company_ID" as "Parent_ID" in the query using some sort of loop?