← All SQL interview questions
Employees earning more than their manager
MediumJoins — Self JoinOracleEXL
An HR compensation review flags reporting pairs where the direct report is paid more than the person they report to.
staff_roster stores the manager as a self-reference in manager_id. Return employee_name, employee_salary, manager_name and manager_salary for every employee whose salary is strictly greater than their manager's salary.
Sample data
Table: staff_roster
14 row(s) · showing first 8
| staff_idINT | staff_nameTEXT | departmentTEXT | manager_idINT | salaryINT |
|---|---|---|---|---|
| 1 | Radhika Anand | Leadership | NULL | 3200000 |
| 2 | Vikram Chandra | Analytics | 1 | 1800000 |
| 3 | Nandini Bose | Analytics | 2 | 1450000 |
| 4 | Imran Shaikh | Analytics | 2 | 1920000 |
| 5 | Kavya Reddy | Data Engineering | 1 | 1750000 |
| 6 | Rohan Dutta | Data Engineering | 5 | 1600000 |
| 7 | Simran Kaur | Data Engineering | 5 | 1810000 |
| 8 | Aakash Verma | Data Science | 1 | 2100000 |
staff_roster
- staff_idINT
- staff_nameTEXT
- departmentTEXT
- manager_idINT
- salaryINT
- Step 1: Both the employee and the manager live in the same table, so join `staff_roster` to itself using two different aliases — `e` for employee, `m` for manager.
- Step 2: The relationship is `m.staff_id = e.manager_id`; read it as “the manager row whose id my `manager_id` points to”.
- Step 3: Use `INNER JOIN` so the top-level employee (whose `manager_id` is `NULL`) is naturally excluded — she has no manager to compare against.
- Step 4: Apply the compensation test `e.salary > m.salary` in `WHERE`.
- Step 5: Alias each projected column so the output clearly separates employee-side and manager-side values.
SELECT e.staff_name AS employee_name,
e.salary AS employee_salary,
m.staff_name AS manager_name,
m.salary AS manager_salary
FROM staff_roster AS e
INNER JOIN staff_roster AS m
ON m.staff_id = e.manager_id
WHERE e.salary > m.salary;Learn the concept first
Stuck on Joins — Self Join? These free SQL lessons teach it step by step.
More Joins — Self Join questions
Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.
Explore the program