An easier method of using compound
conditions uses IN or BETWEEN.
For example, if you wanted to list
all managers and staff:
SELECT EMPLOYEEIDNO
FROM EMPLOYEESTATISTICSTABLE
WHERE POSITION IN ('Manager',
'Staff');
or to list those
making greater than or equal to $30,000,
but less than or equal to $50,000,
use:
SELECT EMPLOYEEIDNO
FROM EMPLOYEESTATISTICSTABLE
WHERE SALARY BETWEEN 30000 AND
50000;
To list everyone not in this range,
try:
SELECT EMPLOYEEIDNO
FROM EMPLOYEESTATISTICSTABLE
WHERE SALARY NOT BETWEEN 30000
AND 50000;
Similarly, NOT IN lists all rows
excluded from the IN list.
Additionally, NOT's
can be thrown in with AND's &
OR's, except that NOT is a unary operator
(evaluates one condition, reversing
its value, whereas, AND's & OR's
evaluate two conditions), and that
all NOT's are performed before any
AND's or OR's.
SQL Order of Logical Operations
(each operates from left to right)
- NOT
- AND
- OR
|