Employees Earning More Than Their Manager

The Problem

Salary inversion - where a direct report earns more than their manager, is a common scenario in organizations. It happens when a senior IC has rare skills, a recently promoted manager hasn't received a pay adjustment, or a new hire negotiated well in a hot market.

Compensation teams flag these during pay equity audits, promotion planning, and budget cycles. A manager who discovers their report earns more is a flight risk. HR wants to find these cases proactively.

The Pattern: Self-Joins

This question tests your ability to join a table to itself, treating one copy as "the employee" and another as "the manager." The key insight is that a foreign key pointing back to the same table's primary key creates a hierarchy you can traverse with a join.

This pattern appears anywhere you have hierarchical or peer relationships in a single table:

  • Org charts - Finding skipped-level reports, comparing team sizes between peer managers
  • Category trees - Products priced higher than their parent category's anchor item
  • Geographic hierarchies - Stores underperforming vs. their region's average
  • Bill of materials - Components that cost more than their parent assembly
  • Referral chains - Users who are more active than the person who referred them
  • Thread/comment trees - Replies that received more upvotes than their parent comment
  • The self-join is also a gateway to understanding recursive CTEs, which generalize this to arbitrary depth.

The Setup

DROP TABLE IF EXISTS employees;
CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    salary DECIMAL(10,2),
    manager_id INT REFERENCES employees(id)
);

INSERT INTO employees (id, name, salary, manager_id) VALUES
(1, 'Alice', 95000, NULL),
(2, 'Bob', 72000, 1),
(3, 'Charlie', 98000, 1),
(4, 'Diana', 85000, 2),
(5, 'Eve', 74000, 2),
(6, 'Frank', 110000, 3),
(7, 'Grace', 65000, 3);
graph TD A[Alice $95k] --> B[Bob $72k] A --> C[Charlie $98k] B --> D[Diana $85k] B --> E[Eve $74k] C --> F[Frank $110k] C --> G[Grace $65k]

The Challenge

Find all employees who earn more than their direct manager. Show the employee name, their salary, manager name, and manager salary.

Think about:

  • Which join type naturally excludes the CEO (NULL manager_id)?
  • Why a JOIN is more idiomatic here than a correlated subquery

Test your solution here

Solution

Click to see the answer
SELECT 
    e.name AS employee,
    e.salary AS employee_salary,
    m.name AS manager,
    m.salary AS manager_salary
FROM employees e
JOIN employees m ON e.manager_id = m.id
WHERE e.salary > m.salary;
  

Discuss on Discord

SQL Output

Getting Started
1Switch to a SQL tab and select a database
2Write or paste your SQL in the editor
3Press Alt+Enter to run
Tip:Select text in the editor to run only that portion
1. Employees Earning More Than Their Manager Updated 1/24/26, 11:24 PM
Notes SQL
Alt+Enter to run