Skip to content
>_sqlbuddy
easyJOINsSelf JoinNULL handling

Employees Earning More Than Their Manager

Find employees whose salary is greater than their direct manager's salary.

Start practice

Prompt

Employees Earning More Than Their Manager

Prompt

Given the employee table below, write a query that returns every employee whose salary is greater than their direct manager's salary.

  • The result should include: employee (the employee's name), employee_salary, manager (the manager's name), and manager_salary.
  • The employee with no manager (the CEO) can never qualify.
  • An employee whose manager_id points to a missing row cannot qualify either.
  • "Greater than" is strictly greater — equal salaries do not qualify.

Example

idnamesalarymanager_id
1Alice100NULL
2Bob801
3Carol1201
4Dave902

Expected result:

employeeemployee_salarymanagermanager_salary
Carol120Alice100
Dave90Bob80

Constraints

  • employee.id is the primary key.
  • employee.manager_id is nullable and references employee.id.

Tips

  • An employee's manager is another row in the same table — use a self join with table aliases.
  • Joining on the unique primary key means no fan-out: one row per employee.

Expected concepts

  • Self join
  • Aliasing
  • Comparison with NULL

Schema

CREATE TABLE employee (
    id         INTEGER PRIMARY KEY,
    name       TEXT NOT NULL,
    salary     INTEGER NOT NULL,
    manager_id INTEGER REFERENCES employee(id)  -- NULL for top-level employees
);

Sample data

INSERT INTO employee (id, name, salary, manager_id) VALUES
  (1, 'Alice', 100, NULL),
  (2, 'Bob',   80,  1),
  (3, 'Carol', 120, 1),
  (4, 'Dave',  90,  2),
  (5, 'Eve',   70,  2);

Additional hidden fixtures are applied during validation to test edge cases.