In a healthy corporate hierarchy, the reporting structure should form a directed acyclic graph (DAG). However, data entry errors can lead to circular dependencies—where Employee A reports to Employee B, who reports to Employee C, who eventually reports back to Employee A.
Write a query to identify all employees who are part of such a circular chain. An employee is considered part of a circular dependency if they appear anywhere within a reporting loop.
| employee_id(INTEGER) | full_name(VARCHAR) | manager_id(INTEGER) |
|---|---|---|
| 1 | Sundar | null |
| 2 | Ruth | 1 |
| 3 | Thomas | 2 |
| 4 | Prabhakar | 3 |
| 5 | Demis | 4 |
| 3 | Thomas | 5 |
| 10 | Jeff | 11 |
| 11 | Sanjay | 10 |
| employee_id(INTEGER) |
|---|
| 3 |
| 4 |
| 5 |
| 10 |
| 11 |