Filter query results using query on different table
suggest changeThis query selects all employees not on the Supervisors table.
SELECT *
FROM Employees
WHERE EmployeeID not in (SELECT EmployeeID
FROM Supervisors)
The same results can be achieved using a LEFT JOIN. If the subquery can return NULL, NOT IN matches nothing, because value NOT IN (..., NULL) is unknown. The join below does not have that problem.
SELECT *
FROM Employees AS e
LEFT JOIN Supervisors AS s ON s.EmployeeID=e.EmployeeID
WHERE s.EmployeeID is NULL
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents