Database Reference
In-Depth Information
Tip
When to Use Quotes If you look closely at the conditions used in the examples'
WHERE
clauses, you will notice that some values are enclosed within single quotes
(such as
'fuses'
used previously), and others are not. The single quotes are used to
delimit strings. If you are comparing a value against a column that is a string
datatype
,
the delimiting quotes are required. Quotes are not used to delimit values used with
numeric columns.
The following is the same example, except this one uses the
!=
operator
instead of
<>
:
▼
Input
SELECT vend_id, prod_name
FROM products
WHERE vend_id != 1003;
Note
!=
Versus
<>
Yes, both
<>
and
!=
look for nonmatches.
!=
means
not equal to
, and
<>
means
less than or greater than
(in other words,
not equal to
). Use whichever you
prefer.
To check for a range of values, you can use the
BETWEEN
operator. Its syntax is
a little different from other
WHERE
clause operators because it requires two val-
ues: the beginning and end of the range. The
BETWEEN
operator can be used,
for example, to check for all products that cost between
5
and
10
or for all
dates that fall between specified start and end dates.
The following example demonstrates the use of the
BETWEEN
operator by
retrieving all products with a price between
5
and
10
:
▼
Input
SELECT prod_name, prod_price
FROM products
WHERE prod_price BETWEEN 5 AND 10;