Recursive CTEs
There are 3 parts to a recursive CTE:
- The anchor member: An initial query that returns the base result of the CTE.
- The recursive member: A recursive query that references the CTE. This is UNION ALL’ed with the anchor member.
- A termination condition that stops the recursive member.
Here is an example of a recursive CTE that gets the manager id for each staff id:
| |