We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
An easy sql problem, graded against 4 test cases (2 of them hidden).
Query-writing problems - joins, aggregation, window functions, and query tuning.
Reach for it when you see: A schema and a question about the data rather than a function signature.
More SQLproblems →```sql
SELECT e.name
FROM Employee e
JOIN Employee m ON e.manager_id = m.id
WHERE e.salary > m.salary
ORDER BY e.name;
```
A self-join treats the same physical table as two logical relations. The `INNER JOIN` skips employees with NULL manager_id (the CEO can't earn more than nobody). Comparing salaries on the joined row gives the answer.
Common interviewer follow-up: "What if managers are several layers up?" - that's a recursive CTE problem (see problem 134).
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.