Ravindra BagaleCourses & study guides Track your progress

7. NULL Values: Missing Data Done Right

7.2 How to Find Missing Values with IS NULL and IS NOT NULL

Why. You must find missing rows before you fix or report them.

What. Use IS NULL and IS NOT NULL — special tests for missing.

How. WHERE note IS NULL / WHERE note IS NOT NULL

Steps

  1. Count rows with missing notes.
  2. List rows that have a note.
  3. Same idea on interview_mini tickets.priority.

Examples

Example 1 · dataset: raja_coffee

SELECT COUNT(*) AS missing_notes
FROM orders
WHERE note IS NULL;

Output

missing_notes
22

Meaning. How many orders have no note.

Example 2 · dataset: interview_mini

SELECT ticket_id, agent, priority
FROM tickets
WHERE priority IS NULL;

Output

ticket_idagentpriority
6James

Meaning. Tickets with unknown priority.

Ravindra Bagale's Tip

IS NULL reads like English — keep using it; do not invent = NULL.