The Employee table holds all employees including their managers. Every employee has an ID, and there is also a column for the manager ID.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerID |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given The Employee table, write a SQL query, finds out employees who earn more than their managers. For the above table, Joe was the only employee of the WHO earns more than his manager.
+----------+
| Employee |
+----------+
| Joe |
+----------+
The problem is to use the Self Join method to select ManagerID and then salary as a comparative condition to get the answer.
# Write your MySQL query statement belowselect a.name from Employee a,employee bwhere a.managerid=b.id and A.SALARY>B.S Alary
Employees earning more Than their Managers leetcode SQL