NOT

You can exclude a condition by putting NOT before it. The following example selects all divisions that are not EASTERN or WESTERN.

This query:

SELECT DEPTNUMB, LOCATION,
 DIVISION FROM Q.ORG
WHERE NOT
 (DIVISION = 'EASTERN' OR DIVISION = 'WESTERN')

Produces this report:

DEPTNUMB LOCATION       DIVISION
-------- -------------  ---------
     10  NEW YORK       CORPORATE
     42  CHICAGO        MIDWEST
     51  DALLAS         MIDWEST

To make it clear what the NOT condition applies to, use parentheses. If you use NOT with AND or OR without parentheses, conditions preceded by NOT are negated before they are connected by AND or OR. That is, if A, B, and C are conditions, these two phrases are equivalent:
NOT A AND
B OR C
means ((NOT A) AND B) OR C

With greater than, less than, or equals, NOT must precede the entire condition, as in WHERE NOT YEARS = 10. You can also negate the equal sign with the not symbol (¬).

These are correct:

This is incorrect:

The symbol ¬= is an alternative operator for < > (not equal to). It is an ANSI SQL operator. If you are using remote data access, the preferred symbol is < >.

[ Previous Page | Next Page | Contents | Index ]