On the Wikipedia page for SQL there are some truth tables about boolean logic in SQL. [1] The Wikipedia page seems to source the SQL:2003 standard.
The truth table f
As the above poster said, null = null
is not correct. It will return NULL(false)
For null comparison you must use IS NULL
or IS NOT NULL
.
That's a new one for me.
If I read that correctly the <boolean value expression>
grammar defines three predicates solely for use with the boolean
datatype IS TRUE
, IS FALSE
, IS UNKNOWN
.
These differ from their equality counterparts in that they only evaluate to True
or False
. Never to Unknown
. i.e. UNKNOWN = TRUE
would evaluate to UNKNOWN
but UNKNOWN IS TRUE
evaluates to False
.
The full truth tables for IS
and =
are below.
+---------+-------+-------+---------+
| IS | TRUE | FALSE | UNKNOWN |
+---------+-------+-------+---------+
| TRUE | TRUE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| UNKNOWN | FALSE | FALSE | TRUE |
+---------+-------+-------+---------+
As opposed to
+---------+---------+---------+---------+
| = | TRUE | FALSE | UNKNOWN |
+---------+---------+---------+---------+
| TRUE | TRUE | FALSE | UNKNOWN |
| FALSE | FALSE | TRUE | UNKNOWN |
| UNKNOWN | UNKNOWN | UNKNOWN | UNKNOWN |
+---------+---------+---------+---------+