How does SQL's three-valued logic work regarding NULL values?
Last updated
NULLmeans unknown, so comparisons with it (evenNULL = NULL) yield UNKNOWN rather than TRUE or FALSE. Test withIS NULL.WHERE,ON, andHAVINGkeep only TRUE rows, discarding FALSE and UNKNOWN.CHECKconstraints pass unless explicitly FALSE.Gotchas:
NOT INwith a NULL in the list can return no rows, and aggregates likeSUMignore NULLs whileCOUNT(*)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/