How does SQL's three-valued logic work regarding NULL values?

Last updated 3 July 2026

  • NULL means unknown, so comparisons with it (even NULL = NULL) yield UNKNOWN rather than TRUE or FALSE. Test with IS NULL.

  • WHERE, ON, and HAVING keep only TRUE rows, discarding FALSE and UNKNOWN. CHECK constraints pass unless explicitly FALSE.

  • Gotchas: NOT IN with a NULL in the list can return no rows, and aggregates like SUM ignore NULLs while COUNT(*) counts all rows.

  • https://www.varsitytutors.com/practice/subjects/sql/lessons/three-valued-logic-and-null
  • https://theartofpostgresql.com/yesql/sql-foundations/null-in-sql/
  • https://www.dbaservices.com.au/blog/understanding-null-in-sql-what-it-means-and-doesnt
  • https://learn.microsoft.com/en-us/sql/t-sql/language-elements/null-and-unknown-transact-sql?view=sql-server-ver17
  • https://www.sqlservertutorial.net/sql-server-basics/sql-server-null/
  • https://sql-tutorial.ru/en/book/second_phase_of_testing/typical_problems/three_valued_logic_and_where_clause/
  • https://www.postgresql.org/docs/current/functions-logical.html
  • https://www.geeksforgeeks.org/sql/sql-null-values/
All SQL interview questions