← All Exercises
Recursive CTE for Hierarchy
advancedsql
Background
Recursive CTEs enable tree and graph traversal in SQL without procedural code.
Problem
Build an org chart traversal using recursive CTE to find all reports under a manager.
Input
Employee table with manager_id
Output
All descendants in hierarchy
Sample tests
Sample 1
Input: manager_id = 1
Expected: all reports
Your solution
Learning objective
Learn recursive queries and hierarchical data traversal