SQL Practice Problem #008

Find employees without a manager

Return employees whose manager_id is NULL.

Problem

Task

Return employees whose manager_id is NULL.

Schema

Table Schema

employees(id, name, department, salary, manager_id)

Input

Sample Data

idnamedepartmentsalarymanager_id
1MinaEngineering70000NULL
2DanielEngineering800001
3SofiaMarketing60000NULL

Output

Expected Output

idnamedepartmentsalarymanager_id
1MinaEngineering70000NULL
3SofiaMarketing60000NULL

Answer

Check Your Solution

Show Answer and Explanation

Correct Answer

SELECT *
FROM employees
WHERE manager_id IS NULL;

Explanation

NULL represents an unknown or missing value. SQL uses IS NULL instead of = NULL because NULL is not equal to any value, including itself.

Common Mistakes

  • Writing manager_id = NULL.
  • Using an empty string check for a numeric manager_id column.
  • Assuming NULL and 0 mean the same thing.

Concepts

Related Concepts

NULL IS NULL Three-Valued Logic WHERE

Next practice

Related Problems