Find missing values with IS NULL
Question
Show the name of employees who have no manager.
employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city
Your query
Ctrl+Enter to run
Result
Expected result
| name |
|---|
| Tom Becker |
| Ana Souza |
| Sofia Rossi |
| Aisha Bello |
Hint
An empty value is NULL, and NULL is tested with IS NULL.
Show the solution
solution.sql
Run this code
SELECT name
FROM employees
WHERE manager_id IS NULL;
Why it works
The heads of each department have no manager, so their manager_id is NULL. IS NULL is true exactly for those rows.
Common mistake
WHERE manager_id = NULL returns no rows at all. Any comparison with NULL is unknown, not true, so always use IS NULL or IS NOT NULL.