The Employees Whose Manager Left the Company interview question asks you to find the IDs of employees who satisfy two conditions: their salary is less than $30,000, and their manager has left the company. An employee's manager has left the company if the manager_id provided in the employee's record no longer exists in the Employee table. The results should be ordered by employee ID.
Companies like Meta and Bloomberg ask this to test a candidate's ability to handle orphaned records and perform negative filtering in SQL. It evaluates knowledge of subqueries (using NOT IN) or LEFT JOIN operations to identify missing relationships. It’s a common data integrity check used in backend systems to clean up pointers to deleted entities.
This is a Relational Filtering problem.
salary < 30000.WHERE manager_id NOT IN (SELECT employee_id FROM Employees) clause to find those whose managers are missing.LEFT JOIN between the employee table and itself and filter where the right side (the manager) is NULL but the manager_id was originally provided.ORDER BY employee_id clause.Employees:
NOT IN with a NULL can behave unexpectedly in some SQL environments. It’s safer to ensure the manager_id is not null before checking existence.INNER JOIN, which would discard the orphaned records you are actually looking for.<= 30000 instead of < 30000.Be careful with NOT IN if the subquery can return NULL values. A safer alternative is often NOT EXISTS or a LEFT JOIN ... WHERE right.id IS NULL. This is a classic SQL nuance that interviewers look for.