Filter query results using query on different table

suggest change

This 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents