Employees Earning More Than Managers

Easy SQLSelf Join

Problem

Schema: Employee(id INT, name VARCHAR, salary INT, manager_id INT). Return the names of employees whose salary is strictly greater than their manager's.

Example 1 Input: Ada salary 100, manager Bo salary 80 Output: "Ada"

Constraints

Approach — Core Patterns

This is a Core Patterns problem. The idea: pick the data structure best matched to the constraints and solve it in one clean pass. Work through the reference code below line by line, then re-derive it yourself in the editor — that's how the pattern sticks.

Complexity: see the walkthrough below.

Solution code

SQL

SELECT e.name
FROM Employee e
JOIN Employee m ON m.id = e.manager_id
WHERE e.salary > m.salary;

Practice it

Reading a solution isn't the same as being able to write it under pressure. Open this problem in the in-browser editor, hide the solution, and solve it from scratch — your code runs against real test cases instantly.

Solve Employees Earning More Than Managers interactively → ← All solutions