Databases Reference
In-Depth Information
As another example:
''List the customer numbers and headquarters cities of the customers that have
a customer number of at least 1700.''
SELECT CUSTNUM, HQCITY
FROM CUSTOMER
WHERE CUSTNUM > =1700;
results in:
CUSTNUM
HQCITY
1700
Washington
1826
New York
2198
New York
2267
New York
ANDs and ORs Frequently, there is a need to specify more than one limiting
condition on a table's rows in a query. Sometimes, for a row to be included in
the result it must satisfy more than one condition. This requires the Boolean AND
operator. Sometimes a row can be included if it satisfies one of two or more
conditions. This requires the Boolean OR operator.
AND
An example in which two conditions must be satisfied is:
''List the customer numbers, customer names, and headquarters cities of the
customers that are headquartered in New York and that have a customer number
higher than 1500.''
SELECT CUSTNUM, CUSTNAME, HQCITY
FROM CUSTOMER
WHERE HQCITY='New York'
AND CUSTNUM > 1500;
resulting in:
CUSTNUM
CUSTNAME
HQCITY
1826
City Hardware
New York
2198
Western Hardware
New York
2267
Central Stores
New York
Notice that customer number 0121, which is headquartered in New York, was
not included in the results because it failed to satisfy the condition of having a
customer number greater than 1500. With the AND operator, it had to satisfy both
conditions to be included in the result.
OR
To look at the OR operator, let's change the last query to:
''List the customer numbers, customer names, and headquarters cities of the
customers that are headquartered in New York or that have a customer number
higher than 1500.''
Search WWH ::




Custom Search