SQL Flow Field Guide

See how NULL changes a filter

Predict how a comparison with NULL affects rows in a WHERE clause.

What you are trying to do

A queue report excludes held tickets. One ticket has no state yet, so the team checks whether a not-equal filter will keep it.

Work through it

  1. Read the three ticket states, including the missing state.
  2. Evaluate State <> N'Hold' for each row.
  3. Check which predicates are TRUE and which rows WHERE returns.

Check your work

Only ticket 1 with state Ready appears. Ticket 2 is FALSE and ticket 3 is UNKNOWN, so neither passes WHERE.

Practice SQL

Open in SQL Flow
SELECT TicketId, State
FROM (VALUES (1, N'Ready'), (2, N'Hold'), (3, NULL)) AS Queue(TicketId, State)
WHERE State <> N'Hold'
ORDER BY TicketId;

Knowledge check

Commands in this lesson

Next lesson Label values with CASE