LESSON 05 / 24·2 min readFoundation

How should I compare NULL values?

01 Understand02 Recall03 Prepare

Understand the concept

SQL NULL represents missing or unknown information, not an ordinary value such as zero or an empty string. Comparisons involving NULL usually produce unknown rather than true or false, and WHERE keeps only true conditions. Special predicates such as IS NULL make the intended check explicit.

Important ideas

  • Use IS NULL or IS NOT NULL, not = NULL.

  • NULL means unknown; ordinary comparisons with NULL are not true.

  • Be careful with NOT IN if the subquery can return NULL; NOT EXISTS is often clearer.

  • COUNT(*) counts rows, while COUNT(column) skips NULL values in that column.

PAUSE & RECALL

Can you explain it without the notes?

How should I compare NULL values?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

SQL NULL represents missing or unknown information, not an ordinary value such as zero or an empty string. Comparisons involving NULL usually produce unknown rather than true or false, and WHERE keeps only true conditions. Special predicates such as IS NULL make the intended check explicit.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Mention three-valued logic and show why = NULL does not find missing values.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Subquery vs EXISTS vs CTE?

Adapted from 05_SQL_POSTGRESQL.md · “How should I compare NULL values?”. Examples are study fragments; framework behavior can depend on your version.