Databases Reference
In-Depth Information
Figure 6-4
(b) CUSTOMER table
CUSTNUM
CUSTNAME
SPNUM
HQCITY
0121
0839
0933
1047
1525
1700
1826
2198
2267
Main St. Hardware
Jane's Stores
ABC Home Stores
Acme Hardware Store
Fred's Tool Stores
XYZ Stores
City Hardware
Western Hardware
Central Stores
137
186
137
137
361
361
137
204
186
New York
Chicago
Los Angeles
Los Angeles
Atlanta
Washington
New York
New York
New York
CUSTOMER table.
First, let's look at an example where we have two conditions and both must
be met for a row to qualify.
List the customer numbers, customer names, and headquarter cities of the
customers that are headquartered in New York and that have a customer
number higher than 1500.
In this case, you would run:
SELECT CUSTNUM, CUSTNAME, HQCITY FROM CUSTOMER
WHERE HQCITY='New York' AND CUSTNUM>1500
This gives us the result:
CUSTNUM CUSTNAME HQCIT
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.
To look at the OR operator, let's change the last query to:
List the customer numbers, customer names, and headquarter cities of the
customers that are headquartered in New York or that have a customer
number higher than 1500.
In this case, you would run:
SELECT CUSTNUM, CUSTNAME, HQCITY FROM CUSTOMER
WHERE HQCITY='New York' OR CUSTNUM>1500
Search WWH ::




Custom Search