NULL vs zero vs empty string

Every cell in a table holds one of 2 things: a value, or a marker saying that no value was recorded. That marker is NULL. It is how a database writes "we don't know" or "this doesn't apply" inside a cell.

Zero and the empty string both look like nothing, yet both are values. 0 is a number that someone measured or typed. '' is a piece of text that happens to contain no characters. NULL marks the absence of any value, which is why a column of any type can hold it: an INTEGER column can, and so can a VARCHAR or BOOLEAN one.

Databases need that marker because the alternative is to invent a value. A made-up birth year or a made-up price looks exactly like a real one, and every report built on the column would treat it as a measurement.

One table, 3 kinds of nothing

A shop keeps a products table. stock is an INTEGER counting units on the shelf, and description is a VARCHAR that the seller types into a form.

product_idnamestockdescription
1Desk Lamp12'Brass, 40cm tall'
2Notebook0'A5, 80 pages'
3MugNULL''
4Backpack7NULL

What each cell says

Why the difference changes answers

A sold-out product and an uncounted product call for different actions. One needs a reorder, the other needs someone to walk to the shelf. If the table stored 0 for both, the question "which products are sold out?" would return products nobody has counted. The query below asks that question, and a second tab asks which descriptions were saved blank.

products
product_idnamestockdescription
1Desk Lamp12Brass, 40cm tall
2Notebook0A5, 80 pages
3MugNULL
4Backpack7NULL

Zero

stock = 0 matches the Notebook only. The Mug's stock is NULL, and a missing count is a different thing from a count of 0.

SELECT
  product_id,
  name,
  stock
FROM products
WHERE stock = 0
Result
product_idnamestock
2Notebook0

Empty string

description = '' matches the Mug only. The Backpack's description is NULL, so it has no text to compare with the empty string.

SELECT
  product_id,
  name,
  description
FROM products
WHERE description = ''
Result
product_idnamedescription
3Mug

Where NULLs come from

NULL enters a table for 4 common reasons, and each one is a different story about the same empty cell.

The cell looks identical in all 4 cases, so the meaning has to come from knowing how the column gets filled.

In the cellA value?Reads as
0Yes, a numberMeasured, and the amount is zero
''Yes, textSaved, with no characters in it
NULLNoNothing was recorded

Deciding what to store is a modelling choice that someone makes for every column. Try it on a tip column in a food delivery app's orders table.

An orders table has a tip column. For which order is NULL the accurate thing to store?

The rest of this lesson keeps coming back to one test: was anything recorded? If something was, the cell holds a value, even when that value is 0 or ''. If nothing was, the cell is NULL, and SQL will refuse to say whether it equals anything at all.

About this lesson

This section is part of the NULL Values: Beginner lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.