| ISSUE 155/456 · COMPUTER SCIENCE |
~4 MIN |
FOUNDATION / DATA / MISSING VALUES · READING DATE 2027-03-05 · MARCH 2027 — DATA AND HEAT
Why not equal does not include a missing answer
START HERE
A form can contain a postcode, an empty answer, or no recorded answer at all. A database stores records for later searching and calculation. NULL is a special database marker for a missing value, rather than an ordinary number or piece of text. Comparing an unknown value with a known one usually gives an unknown answer, not automatically yes or no.
|
/ WHY NOW
A mailing list can lose people when you ask for everyone whose town is not London. If missing towns are handled as ordinary non-London towns in your head, the returned list will surprise you.
|
/ THE IDEA
SQL, a language for asking database questions, uses three possible results for many tests: TRUE, FALSE and UNKNOWN. WHERE keeps only rows for which its condition is TRUE. Rows whose test is UNKNOWN are left out along with the FALSE rows, but those two results are not logically interchangeable. Suppose a missing town might turn out to be London or Leeds. The statement town = 'London' cannot yet be decided. The quotation marks identify literal text, and <> means not equal. Negating an undecidable statement does not reveal the missing information: NOT UNKNOWN is still UNKNOWN. To select missing values explicitly, SQL provides IS NULL rather than equality to NULL.
THE FORMAL IDEA
NULL = x → UNKNOWN; NOT UNKNOWN → UNKNOWN
| NULL is the missing marker; x stands for an ordinary known value. The arrow means the comparison produces the result on its right. | | UNKNOWN is a result of the test, not a hidden town. IS NULL asks whether the marker is present and gives a definite true-or-false answer. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Rows: Asha = London, Ben = Leeds, Cara = NULL. WHERE town <> 'London' tests FALSE, TRUE, UNKNOWN; only Ben is returned. Change only Cara’s town from NULL to York. The same filter now tests FALSE, TRUE, TRUE and returns Ben plus Cara.
|
Nothing about Cara’s identity changed. Recording a known town changed whether the database could establish that she met the condition. If the intended policy includes unknown towns, town <> 'London' OR town IS NULL returns both Ben and Cara even in the original input.
/ SO WHAT?
The extra truth value matters in combined tests too. TRUE OR UNKNOWN is TRUE because the first part already settles the question. FALSE AND UNKNOWN is FALSE because one required part has already failed. These rules preserve what can be concluded without pretending that missing information has a value. They explain many apparently disappearing records.
ONE CAVEAT |
| NULL can represent different real-world reasons, including unavailable, inapplicable or not yet collected. The marker does not distinguish them. Empty text and zero are ordinary values, so substituting either changes meaning and may hide an important data-quality problem. |
KEEP THIS
When missing answers should count, name that policy explicitly instead of assuming that not equal means known to be different.
|
NEXT: Why a long metal part needs room to grow
|