Counting Rows and Counting Recorded Values Can Produce Different Answers

Conceptual desk scene with a notebook, a pressed leaf and blank cards beside a laptop.
Conceptual illustration created with AI; not a research result or laboratory photograph.

A table has four rows, but one field contains a missing value. How many observations are there? The answer depends on whether you mean rows, recorded values in that field, or distinct recorded values.

Consider a fictional column containing A, A, B and NULL. In PostgreSQL, count(*) returns four; count(column) returns three; count(distinct column) returns two. The aggregate-function documentation explains the treatment of null inputs.

Name the number you publish

“Four records, three with a recorded category” describes the example more clearly than a single unlabeled count. It also prevents a later reader from assuming that a smaller count means rows were deleted.

An empty string is not the same database value as NULL. Before applying the example to a real dataset, inspect how missing information was encoded. A dash, a space and the text “unknown” may require a documented cleaning decision.

Try the count on a tiny table whose expected result you can calculate by hand. Then preserve the query alongside the output.

The calculation is straightforward; the difficult part is choosing a count that answers the actual question and labelling it so that another person can recover that choice.