SQL NULL explorer
Change the values. Compare the predicates. See exactly which rows WHERE keeps.
Choose your inputs
Enter up to 20 integers per list, from -1000000 to 1000000. Use NULL for a missing value. Leave the exclusion list empty to test an empty subquery. Duplicate candidates remain separate rows.
WHERE results: NOT IN
0 of 3 rows kept · WHERE keeps TRUE and drops FALSE or UNKNOWN.
| Row | Candidate | Predicate result | WHERE action | Why |
|---|---|---|---|---|
| 1 | 10 | UNKNOWN | DROP | No equal known key was found, but the exclusion list contains NULL. WHERE drops UNKNOWN. |
| 2 | 20 | FALSE | DROP | An equal known exclusion key exists. |
| 3 | NULL | UNKNOWN | DROP | Ordinary comparisons cannot establish equality or inequality for this NULL key. WHERE drops UNKNOWN. |
Returned row IDs: None
Compare all four policies
Changing the treatment of NULL changes the rule. These columns help you see that difference before choosing a rewrite.
| Row / value | IN | NOT IN | NOT EXISTS with ordinary equality | NOT IN with non-null guards | NOT EXISTS with NULL matching NULL |
|---|---|---|---|---|---|
| 1 / 10 | UNKNOWN | UNKNOWN | TRUE | TRUE | TRUE |
| 2 / 20 | TRUE | FALSE | FALSE | FALSE | FALSE |
| 3 / NULL | UNKNOWN | UNKNOWN | TRUE | FALSE | FALSE |
Run the same case in your database
Select and copy this read-only query. It creates its input rows in CTEs and does not modify tables. Verify syntax and behavior on your database engine.
WITH candidates (row_id, customer_id) AS (
VALUES (1, 10), (2, 20), (3, NULL)
),
blocked (customer_id) AS (
VALUES (20), (NULL)
)
SELECT c.row_id, c.customer_id
FROM candidates AS c
WHERE c.customer_id NOT IN (SELECT b.customer_id FROM blocked AS b)
ORDER BY c.row_id;How to interpret the result
NULL represents a missing or unknown value. Ordinary equality cannot establish that NULL equals NULL. For a nonempty right-hand set, NOT IN can be UNKNOWN when no equal known value exists but a comparison involves NULL. An empty subquery is a separate case: scalar NOT IN is TRUE.
NOT EXISTS with ordinary equality can keep a candidate whose key is NULL. The guarded policy rejects missing candidate keys explicitly. The NULL-matching policy intentionally treats two missing keys as a match. Decide which rule your application needs before switching syntax.
This is a focused learning model for scalar integers and NULL, not a general SQL engine. It does not model text collation, type coercion, composite keys, performance, or every database dialect. Inputs appear in the page URL when you submit; use learning values rather than real customer identifiers.
Read the full NOT IN and NULL troubleshooting guide →
Explore duplicate matches and unmatched rows in SQL JOIN →