Employees Whose Manager Left the Company - Problem

You are given an Employees table with information about employees, their salaries, and their managers.

Task: Find the IDs of employees who meet both conditions:

  • Their salary is strictly less than $30,000
  • Their manager has left the company (manager exists in manager_id but not in the table)

When a manager leaves, their record is deleted from the table, but their former reports still have the manager_id pointing to the deleted manager.

Return results ordered by employee_id.

Table Schema

Employees
Column Name Type Description
employee_id PK int Primary key, unique employee identifier
name varchar Employee's full name
manager_id int ID of the employee's manager, can be null
salary int Employee's salary in dollars
Primary Key: employee_id
Note: Some employees have no manager (manager_id is null). When managers leave, their records are deleted but manager_id references remain.

Input & Output

Example 1 — Employees with Missing Managers
Input Table:
employee_id name manager_id salary
3 Mila 9 60000
12 Antonella 9 25000
13 Emery 9 28000
Output:
employee_id
12
13
💡 Note:

Employees 12 and 13 both have manager_id = 9, but there's no employee with employee_id = 9 in the table (the manager left). Employee 3 also has the same missing manager but earns 60000 ≥ 30000, so they're excluded. Only employees 12 and 13 meet both conditions: salary < 30000 AND manager left.

Example 2 — No Qualifying Employees
Input Table:
employee_id name manager_id salary
1 Boss 80000
2 John 1 25000
Output:
employee_id
💡 Note:

Employee 1 is the boss with no manager (manager_id = null). Employee 2 has a valid manager (employee 1 exists) and salary < 30000, but since their manager didn't leave, they don't qualify. No employees meet both conditions.

Example 3 — Mixed Scenarios
Input Table:
employee_id name manager_id salary
1 Alice 50000
5 Bob 7 28000
6 Carol 7 35000
Output:
employee_id
5
💡 Note:

Alice has no manager. Both Bob and Carol have manager_id = 7 (missing manager), but only Bob has salary < 30000. Carol's salary is 35000 ≥ 30000, so she's excluded.

Constraints

  • 1 ≤ employee_id ≤ 100
  • 1 ≤ name.length ≤ 20
  • 1 ≤ manager_id ≤ 100
  • 0 ≤ salary ≤ 100000

Visualization

Tap to expand
Finding Employees with Missing ManagersInput: Employeesemployee_idnamemanager_idsalary3Mila96000012Antonella92500013Emery928000LEFT JOIN+ FilterOutputemployee_id1213Manager ID 9 missing from tableEmployees 12, 13: salary < 30000 ✓Employee 3: salary ≥ 30000 ✗
Understanding the Visualization
1
Input
Employees table with some missing manager IDs
2
LEFT JOIN
Self-join to find missing manager references
3
Filter
Apply salary and NULL manager conditions
Key Takeaway
🎯 Key Insight: Use LEFT JOIN to detect missing references and filter orphaned relationships
Asked in
Amazon 23 Microsoft 18 Google 15
28.0K Views
Medium Frequency
~12 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen