← All SQL interview questions

Build each employee's reporting chain to the CEO

HardRecursive CTEsTargetOracle

An access-review tool must display the full escalation chain for each person.

org_members stores reports_to as a self-reference; the CEO's is NULL. Using a recursive CTE, return member_id, member_name, levels_from_top (0 for the CEO) and chain — the names from the CEO down to that member joined with -> .

Sample data

Table: org_members

15 row(s) · showing first 8

member_idINTmember_nameTEXTtitleTEXTreports_toINT
1Radhika AnandCEONULL
2Aakash VermaVP Data1
3Kavya ReddyVP Engineering1
4Vikram ChandraDirector Analytics2
5Zoya MirzaDirector Science2
6Simran KaurDirector Platform3
7Nandini BoseAnalytics Manager4
8Imran ShaikhAnalytics Manager4

Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.

Explore the program