Skip to content
Advertisement

Recursive CTE in Postgres

I have a table with the structure:

And, for each employee, I need to show the top manager ID. I mean, if for example, I have the EmployeeID 2 whose manager is 3 and, therefore, the number 3 has the manager number 5, I would have to show:

I need to do this with a Recursive CTE in Postgres.

Advertisement

Answer

Something like (for the level 2 manager) :

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement