6.5. NULLs and Logic

George Boole developed two-valued logic and attached his name to Boolean algebra forever (Boole 1854). This is not the only possible system, but it is the one that works best with a binary (two-state) computer and with a lot of mathematics. SQL has three-valued logic: TRUE, FALSE, and UNKNOWN. The UNKNOWN value results from using NULLs in comparisons and other predicates, but UNKNOWN is a logical value and not the same as a NULL, which is a data value marker. That is why you have to say (x IS [NOT] NULL) in SQL and not use (x = NULL) instead. Table 6.1 shows the tables for the three operators that come with SQL.

Table 6.1. SQL’s Three Operators
x NOT ================== TRUE FALSE UNK UNK FALSE TRUE AND | TRUE UNK FALSE ============================= ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.