(Contents)(Previous)(Next)

NOT with NULL, LIKE, IN, BETWEEN

NULL, LIKE, IN, and BETWEEN are operators which can be preceded by NOT. In the case of NULL, the word 'IS' is needed. The condition

WHERE NOT (firstname IS NULL)

can also be written as

WHERE firstname IS NOT NULL.

Find all customers who have a first name, i.e., are not companies:

SELECT firstname, name, city

FROM customer

WHERE firstname IS NOT NULL

Find the customers who are not a company:

SELECT name, city

FROM customer

WHERE title NOT LIKE 'Co%'

Find the customers who do not live in Dallas or New York:

SELECT name, city, state, zip

FROM customer

WHERE city NOT IN ('Dallas','New York')

Find the customers who have either a positive account or a considerable negative account:

SELECT title, name, city, account

FROM customer

WHERE account NOT BETWEEN -10 AND 0

The preceding example can also be formulated differently:

SELECT title, name, city, account

FROM customer

WHERE NOT (account >= -10 AND ACCOUNT <= 0)

or else:

SELECT title, name, city, account

FROM customer

WHERE account < -10 OR account > 0


(Contents)(Previous)(Next)