7. Employees Earning More Than Their Managers

Easy
#Joins#Self Join

Problem Description

Write a SQL query to find employees who earn more than their managers. ### Example **Employee Table:** | id | name | salary | managerId | | :--- | :--- | :--- | :--- | | 1 | Joe | 70000 | 3 | | 2 | Henry | 80000 | 4 | | 3 | Sam | 60000 | NULL | | 4 | Max | 90000 | NULL | **Expected Output:** | Employee | | :--- | | Joe |

Database Schema

undefined

Sample SQL Solution

-- Self join the Employee table
SELECT e.name AS Employee
FROM Employee e
JOIN Employee m ON e.managerId = m.id
WHERE e.salary > m.salary;