Chapter 3: Selecting
Chapter 3: Selecting
The IS and IS NOT operators can be used to test the result of a predicate or
boolean expression. These operators have the advantage that they always return
TRUE or FALSE, never UNKNOWN. Here are some examples showing the
results of IS and IS NOT operators:
X contains:
====================
Boolean Expression NULL 0 1
======================== ====== ===== =====
( X = 0 ) IS TRUE FALSE TRUE FALSE
( X = 0 ) IS FALSE FALSE FALSE TRUE
( X = 0 ) IS UNKNOWN TRUE FALSE FALSE
( X = 0 ) IS NOT TRUE TRUE FALSE TRUE
( X = 0 ) IS NOT FALSE TRUE TRUE FALSE
( X = 0 ) IS NOT UNKNOWN FALSE TRUE TRUE
The IS UNKNOWN operator is rarely used because for most purposes,
UNKNOWN is the same as FALSE. With a WHERE clause, for example, a row
yielding either UNKNOWN or FALSE will be eliminated.
The NOT, AND, and OR operators can be used to change and combine
intermediate TRUE, FALSE, and UNKNOWN results according to the follow-
ing truth tables. For example, if a <boolean_expression> results in TRUE,
then NOT <boolean_expression> is FALSE. Note that you cannot actually code
NOT TRUE in SQL Anywhere; the following tables are simply a shorthand
for explaining what happens when you code something like NOT X = 1:
NOT Result
=========== ======
NOT TRUE FALSE
NOT FALSE TRUE
NOT UNKNOWN UNKNOWN
AND Result
================== ======
TRUE AND TRUE TRUE
TRUE AND FALSE FALSE
TRUE AND UNKNOWN UNKNOWN
FALSE AND TRUE FALSE
FALSE AND FALSE FALSE
FALSE AND UNKNOWN FALSE
UNKNOWN AND TRUE UNKNOWN
UNKNOWN AND FALSE FALSE
UNKNOWN AND UNKNOWN UNKNOWN
OR Result
================== ======
TRUE OR TRUE TRUE
TRUE OR FALSE TRUE
TRUE OR UNKNOWN TRUE
FALSE OR TRUE TRUE
FALSE OR FALSE FALSE
FALSE OR UNKNOWN UNKNOWN
UNKNOWN OR TRUE TRUE
UNKNOWN OR FALSE UNKNOWN
UNKNOWN OR UNKNOWN UNKNOWN