SELECT Statements SQL Topic exerciseEasyVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

SELECT with NULL Handling

Return employees who do not have a manager.

  • NULL handling
  • Filtering

Exercise brief

Understand the request

Org design lead The org-chart review starts with employees who do not report to anyone.

Return first_name, last_name, and manager_id for every employee who does not report to a manager (manager_id is NULL).

Return

  • Return first_name, last_name, and manager_id.

Constraints

  • Filter with IS NULL on manager_id.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

employees

  • first_nameVARCHAR(50)
  • last_nameVARCHAR(50)
  • manager_idINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

NULL is "unknown" — comparing it with `=` always returns NULL, never true. Use IS NULL / IS NOT NULL instead.

Hint 2

`WHERE manager_id = NULL` returns 0 rows. `WHERE manager_id IS NULL` is what you want.

Hint 3

Project the requested employee fields, then test manager_id with IS NULL.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT first_name, last_name, manager_id FROM employees WHERE manager_id IS NULL;

Why this works

SQL has three-valued logic: TRUE, FALSE, UNKNOWN (NULL). Equality comparisons against NULL evaluate to UNKNOWN, which WHERE treats as "do not include this row". The IS NULL / IS NOT NULL operators are the only way to test for the NULL state.

Expected result

Use this output to verify values, aliases, ordering, and row count.

first_namelast_namemanager_id
JohnSmithNULL
CarolDavisNULL
DavidBrownNULL
EmmaTaylorNULL

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.