Mid
DML & Subqueries
SQL & Databases
How do you remove all employees in departments with no managers assigned?
Short answer: DELETE with WHERE DepartmentId IN (departments where ManagerId IS NULL) or use JOIN. Preview with SELECT first.
Sample solution
T-SQL
DELETE e FROM Employees e INNER JOIN Departments d ON d.DepartmentId = e.DepartmentId WHERE d.ManagerId IS NULL;
In interviews, always say you would run SELECT with the same FROM/WHERE before DELETE.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png