Datasheet

Writing Simple Queries
33
Logical Operators
Logical operators are used to combine the results of two comparison conditions (compound
conditions) to produce a single result or to reverse the result of a single comparison.
NOT,
AND, and OR are the logical operators. When a logical operator is applied to NULL, the result
is
UNKNOWN. UNKNOWN acts similarly to FALSE; the only difference is that NOT FALSE is TRUE,
whereas
NOT UNKNOWN is also UNKNOWN.
NOT
You can use the NOT operator to reverse the result. It evaluates to TRUE if the operand is
FALSE, and it evaluates to FALSE if the operand is TRUE. NOT returns NULL if the operand
is
NULL.
WHERE !(department_id >= 30)
*
ERROR at line 3:
SELECT first_name, department_id
FROM employees
WHERE not (department_id >= 30);
FIRST_NAME DEPARTMENT_ID
-------------------- -------------
Jennifer 10
Michael 20
Pat 20
AND
The AND operator evaluates to TRUE if both operands are TRUE. It evaluates to FALSE if either
operand is
FALSE. Otherwise, it returns NULL.
SELECT first_name, salary
FROM employees
WHERE last_name = ‘Smith’
AND salary > 7500;
FIRST_NAME SALARY
-------------------- ----------
Lindsey 8000
95127c01.indd 33 2/18/09 6:37:10 AM