Contents Index The WHERE clause: specifying rows Using ranges (between and not between) in the WHERE clause

ASA SQL User's Guide
  Queries: Selecting Data from a Table
    The WHERE clause: specifying rows

Using comparison operators in the WHERE clause


You can use comparison operators in the WHERE clause. The operators follow the syntax:

WHERE expression comparison-operator expression

For more information about comparison operators, see Comparison operators. For a description of what an expression can consist of, see Expressions.

Notes on comparisons 

Here are some SELECT statements using comparison operators:

SELECT *
FROM product
WHERE quantity < 20
SELECT E.emp_lname, E.emp_fname
FROM employee E
WHERE emp_lname > 'McBadden'
SELECT id, phone
FROM contact
WHERE state  != 'CA'
The NOT operator 

The NOT operator negates an expression. Either of the following two queries will find all Tee shirts and baseball caps that cost $10 or less. However, note the difference in position between the negative logical operator (NOT) and the negative comparison operator (!>).

SELECT id, name, quantity
FROM product
WHERE (name = 'Tee Shirt' OR name = 'BaseBall Cap')
AND NOT unit_price > 10
SELECT id, name, quantity
FROM product
WHERE (name = 'Tee Shirt' OR name = 'BaseBall Cap')
AND unit_price !> 10

Contents Index The WHERE clause: specifying rows Using ranges (between and not between) in the WHERE clause