Skip to content
RED SAGSkills
medium30 ptsSelf Join

Employees Who Out-Earn Their Manager

In employees, manager_id refers to another row of the same table. Find employees whose salary is strictly greater than their direct manager's salary. Ignore employees without a manager, or whose manager is not in the table.

Return columns employee_name, manager_name. Row order does not matter.

Schema

CREATE TABLE employees (
  emp_id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  salary INTEGER NOT NULL,
  manager_id INTEGER
);

Sample data

employees

emp_idnamesalarymanager_id
1Nour20000NULL
2Owen120001
3Paz210001
4Qadir125002
5Rhea110002
6Stan90003
Hint 1

Join the table to itself: one copy for employees, one for managers.

Hint 2

An inner join drops employees whose manager_id has no matching row.

Good practice for: Data Analyst, Backend Developer, Business Analyst, Database Administrator

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.