Skip to content
Part IA Michaelmas Term

NULL and Three-Valued Logic

What NULL is not

NULL is not the empty string, zero, or the boolean false. NULL is a place-holder, not a value. NULL is not a member of any domain (type).

Three-valued logic

Because NULL represents “we don’t know”, we need three-valued logic (3VL). Let \bot (or UNKNOWN) represent the third truth value. The truth tables extend Boolean logic:

AND (\land)

\landTTFF\bot
TTTTFF\bot
FFFFFFFF
\bot\botFF\bot

OR (\lor)

\lorTTFF\bot
TTTTTTTT
FFTTFF\bot
\botTT\bot\bot

NOT (¬\neg)

¬\negResult
TTFF
FFTT
\bot\bot

Key observations:

  • F=F\bot \land F = F (one false makes the conjunction false, regardless of unknowns).
  • T=T\bot \lor T = T (one true makes the disjunction true).
  • ¬=\neg \bot = \bot (the negation of unknown is unknown).

Unexpected NULL behaviour

NULL can lead to surprising results:

SELECT * FROM students WHERE age <> 19;

This does not return rows where age IS NULL. Any comparison with NULL yields \bot, and only rows where the WHERE clause evaluates to TT are included in the result. A row where age IS NULL evaluates age <> 19 to \bot, which is not TT, so the row is excluded.

Interpretations of NULL

There are several possible interpretations of NULL, creating what the lecture calls “a great deal of semantic muddle”:

InterpretationMeaning
Missing valueThere is a value, but we don’t know what it is
InapplicableNo value is applicable (e.g., spouse for an unmarried person)
Hidden valueThe value exists but you are not allowed to see it

SQL’s definition

SQL’s definition: “NULL is not equal to anything — not even to another NULL.” This avoids the “common sister” paradox where two rows with unknown values could be spuriously equated.

The IS NULL predicate

IS NULL is the standard way to test for NULL. Unlike comparisons, IS NULL evaluates to either TT or FF — never \bot:

SELECT * FROM students WHERE age IS NULL;

Similarly, IS NOT NULL returns TT or FF.

The NULL controversy

C.J. Date (a prominent relational theorist) argues that NULLs and 3VL are “a serious mistake” that “have no place in the relational model.” His criticism: NULLs violate the relational model’s logical foundations and create subtle inconsistencies.

Defender argument: NULLs serve an important practical role in handling incomplete information. The flaws should be repaired rather than abandoning NULLs entirely.

SQL inconsistency: GROUP BY on NULLs

Consider a GROUP BY on a column that contains NULLs:

SELECT col, COUNT(*) FROM t GROUP BY col;

SQL treats all NULL values as equivalent for grouping purposes — they form a single group. This contradicts the principle that “NULL is not equal to anything — not even to another NULL.” Under the rule that NULLNULL\text{NULL} \neq \text{NULL}, each NULL would belong to its own group, but SQL groups them together.

Summary

  • NULL is a place-holder, not a value, and not a member of any domain.
  • Three-valued logic extends boolean truth tables with \bot (UNKNOWN).
  • Comparisons with NULL produce \bot; only TT satisfies WHERE.
  • Use IS NULL / IS NOT NULL to test for NULL reliably.
  • NULL has multiple interpretations: missing, inapplicable, or hidden.
  • C.J. Date criticises NULLs as a relational model violation.
  • GROUP BY inconsistently treats all NULLs as one group.