Employees Whose Manager Left the Company
Task: Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves, their information is deleted.
Table: Employees
| Column Name | Type |
|---|---|
| employee_id | INT |
| name | varchar(20) |
| manager_id | INT |
| salary | INT |
Input: Employees table:
| employee_id | name | manager_id | salary |
|---|---|---|---|
| 3 | Mila | 9 | 60301 |
| 12 | Antonella | null | 31000 |
| 13 | Emery | null | 67084 |
| 1 | Kalel | 11 | 21241 |
| 9 | Mikaela | null | 50937 |
| 11 | Joziah | 6 | 28485 |
Output:
| employee_id |
|---|
| 11 |
View Reference Solution & Explanation ▼
This solution uses a subquery to filter records based on another query's result to find the required output.
SELECT employee_id FROM Employees WHERE salary < 30000 AND manager_id NOT IN (SELECT employee_id FROM Employees) ORDER BY employee_id;