Meridian Group's HR team needs to answer questions that require walking the entire management hierarchy: who reports (directly or indirectly) to a given manager, how deep each person sits in the org, and what their full reporting path looks like. A standard SQL query cannot do this. You need a recursive CTE โ a query that calls itself repeatedly until no more rows are returned.
employees(id, name, title, manager_id, department)
Rows: 1 CEO โ 3 VPs โ 9 Directors โ 24 Managers โ 48 ICs = 85 total. manager_id is NULL for the CEO (root node).
WHERE manager_id IS NULL โ this returns just the CEOJOIN org_tree ON e.manager_id = org_tree.iddepth + 1 to track hierarchy levelCONCAT(path, ' > ', e.name) to build full reporting pathWHERE id = 3The Reference window has a complete working template. Type or paste the full WITH RECURSIVE block โ the terminal recognises the key clauses. The Org Chart window visualises the result after each successful run.