Menu
Coddy logo textTech

Recap - Org Chart

Part of the Beyond the Basics section of Coddy's SQL journey — lesson 22 of 27.

challenge icon

Challenge

Medium

Available tables and columns:

  • <strong>employees</strong>: <strong>id</strong>, <strong>name</strong>, <strong>manager_id</strong>

For the employee with id = 7, return the chain of managers above them: their direct manager, their manager's manager, and so on up to the top of the org. Return id and name, ordered from the closest manager (lowest depth) to the most senior. Do not include employee 7 themselves.

Try it yourself

WITH RECURSIVE chain AS (
    -- start from employee 7's manager
    -- recurse upward via manager_id
)
SELECT id, name FROM chain ORDER BY depth

All lessons in Beyond the Basics