Easy Filtering rows Employees database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

name
Tom Becker
Ana Souza
Sofia Rossi
Aisha Bello

Rows can come in any order. Column names do not have to match.

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.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.