20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

It’s as simple as that! The IN operator checks the database to see if the specified column matches one or<br />

more of the values listed inside the brackets. You can use the IN operator with any data type, not just<br />

text as shown above. The preceding <strong>SQL</strong> produces the following results:<br />

City<br />

Townsville<br />

Townsville<br />

Big City<br />

Windy Village<br />

Windy Village<br />

Big City<br />

Dover<br />

Chapter 8 shows you how to use a <strong>SQL</strong> SELECT statement instead of a list of literal values. In the following<br />

Try It Out, however, you stick with the IN operator and literal values.<br />

Try It Out Using the IN Operator<br />

1. Using the following <strong>SQL</strong>, query the Film Club database to see which films were released in<br />

1967, 1977, or 1987 and have a rating of either 4 or 5. Include FilmName, YearReleased, and<br />

Rating in the search.<br />

SELECT FilmName, YearReleased, Rating<br />

FROM Films<br />

WHERE<br />

YearReleased IN (1967, 1977, 1987)<br />

AND<br />

Rating IN (4,5);<br />

2. Execute the <strong>SQL</strong>.<br />

How It Works<br />

74<br />

The SELECT statement simply specifies the database and the fields to search:<br />

SELECT FilmName, YearReleased, Rating<br />

FROM Films<br />

The WHERE clause employs the IN operator to search for a film’s year of release:<br />

YearReleased IN (1967, 1977, 1987)<br />

Use the IN operator again to search for films with a rating of either 4 or 5:<br />

Rating IN (4,5)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!