Employees Earning More Than Their Manager
Find every employee whose salary is strictly greater than their direct manager's salary. Return employee_name, employee_salary, manager_name, manager_salary — ordered by employee_name, employee_id.
- Joins
- Filtering
- Sorting
Exercise brief
Understand the request
Compensation governance analyst A pay review needs defensible employee-to-manager comparisons at direct-report grain.
Return
- Return employee and manager names with both salaries.
- Order deterministically by employee name and ID.
Constraints
- Use the manager_id relationship.
- Use a strict salary comparison.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
employee_idINTEGERemployee_nameTEXTmanager_idINTEGERsalaryINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Self-join, then a WHERE that compares two columns from the SAME table (different aliases).
Hint 2
INNER JOIN here — the question is meaningless for employees with no manager.
Hint 3
Tie-breaker on employee_id keeps results stable when two employees share the same name.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT e.employee_name, e.salary AS employee_salary, m.employee_name AS manager_name, m.salary AS manager_salary FROM employees e INNER JOIN employees m ON e.manager_id = m.employee_id WHERE e.salary > m.salary ORDER BY e.employee_name, e.employee_id;Why this works
Cross-row comparisons inside the same table are exactly what self-joins are for. Once aliased, e.salary and m.salary look like columns from two different tables to the optimizer.
Success check
Only employees strictly above their direct manager are returned.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| employee_name | employee_salary | manager_name | manager_salary |
|---|---|---|---|
| Mia Overpaid Jr | 125000 | Emma Sales Mgr | 120000 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
SQL Joins
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
CTEs & Window Functions
Practice modular CTE pipelines, deterministic window analytics, period comparisons, deduplication, frames, and gaps-and-islands.
SQL Subqueries
Practice scalar, derived-table, correlated, EXISTS, NULL-safe anti-subquery, quantified, and row-subquery patterns.
Open the interactive workspace and practice across SQL topics.