Lesson 1 of 0
In Progress

Employees Who Have Managers Earning Less

Kedeisha June 8, 2023

Challenge

Consider a table: Employees.

The Employees table has columns: id (int), name (varchar), salary (decimal), and manager_id (int).

Write a SQL query to find the employees who earn more than their managers.

 

DB Fiddle Instructions

Click ‘Edit on DB Fiddle’ to be taken to the in browser SQL playground where you can run your queries.

Explanation

This query uses a self join to pair each employee with their manager. Then, it uses the WHERE clause to filter out the pairs where the employee’s salary is greater than the manager’s salary.