Reason correctly about NULL in SQL

8 steps · about 2 h 25 min · Intermediate

  1. Distinguish SQL NULL from a value (reference, PostgreSQL Global Development Group, 10 min)

    Sets the type context before exploring why NULL is not an empty string, zero or ordinary sentinel.

  2. Use NULL-aware comparisons (guide, PostgreSQL Global Development Group, 20 min)

    Documents IS NULL, IS DISTINCT FROM and the unknown results produced by ordinary comparison.

  3. Trace three-valued logic (guide, PostgreSQL Global Development Group, 15 min)

    Truth tables make AND, OR and NOT behavior predictable when one input is unknown.

  4. Choose COALESCE and CASE deliberately (guide, PostgreSQL Global Development Group, 20 min)

    Shows when to substitute a display value and when preserving missingness is the more honest choice.

  5. Check how aggregates treat NULL (guide, PostgreSQL Global Development Group, 20 min)

    Highlights the important difference between COUNT(*) and COUNT(column) and how missing inputs affect results.

  6. Understand NULL in constraints (reference, PostgreSQL Global Development Group, 25 min)

    Explains not-null, unique, check and foreign-key clauses so missing values are constrained intentionally.

  7. Connect unknown logic across clauses (guide, Modern SQL, 20 min)

    Brings filters, joins and constraints together around one consistent three-valued model.

  8. Practise a NULL-aware filter (interactive, PostgreSQL Exercises, 15 min)

    A small PostgreSQL exercise gives immediate feedback on selecting rows whose value is missing.