Database Reference
In-Depth Information
Similarly, to find all of the rows of SKU_DATA for either the Camping or Climbing depart-
ments, we can use the SQL OR operator in the SQL query:
/* *** SQL-Query-CH02-16 *** */
SELECT *
FROM SKU_DATA
WHERE Department='Camping'
OR Department='Climbing';
which gives us the following results:
Three or more AND and OR conditions can be combined, but in such cases the SQL IN
operator and the SQL NOT IN operator are easier to use. For example, suppose we want to
obtain all of the rows in SKU_DATA for buyers Nancy Meyers, Cindy Lo, and Jerry Martin. We
could construct a WHERE clause with two ANDs, but an easier way to do this is to use the IN
operator, as illustrated in the SQL query:
/* *** SQL-Query-CH02-17 *** */
SELECT *
FROM
SKU_DATA
WHERE
Buyer IN ('Nancy Meyers', 'Cindy Lo', 'Jerry Martin');
In this format, a set of values is enclosed in parentheses. A row is selected if Buyer is equal to
any one of the values provided. The result is:
Similarly, if we want to find rows of SKU_DATA for which the buyer is someone other than
Nancy Meyers, Cindy Lo, or Jerry Martin, we would use the SQL query:
/* *** SQL-Query-CH02-18 *** */
SELECT *
FROM
SKU_DATA
WHERE
Buyer NOT IN ('Nancy Meyers', 'Cindy Lo', 'Jerry Martin');
The result is:
 
 
Search WWH ::




Custom Search