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.

The final condition required is a check to see if the film is available on DVD. Again, the compulsory condition<br />

is matched. If you want the right answer to the question, an AND statement must be used. This<br />

condition is fairly simple, just a check if the AvailableOnDVD column contains a single character Y:<br />

WHERE ( YearReleased BETWEEN 1980 AND 1989 )<br />

AND<br />

( Rating BETWEEN 2 AND 4 )<br />

AND<br />

AvailableOnDVD = ‘Y’<br />

Putting it all together, you have the following <strong>SQL</strong>:<br />

SELECT FilmName, YearReleased, Rating, AvailableOnDVD<br />

FROM Films<br />

WHERE ( YearReleased BETWEEN 1980 AND 1989 )<br />

AND<br />

( Rating BETWEEN 2 AND 4 )<br />

AND<br />

( AvailableOnDVD = ‘Y’ )<br />

Execute the <strong>SQL</strong> and the result is just one record:<br />

FilmName YearReleased Rating AvailableOnDVD<br />

Gone with the Window Cleaner 1988 3 Y<br />

The SELECT clause of the second query is also quite straightforward. It simply asks the database system<br />

to retrieve records from the FilmName column of the Films table:<br />

SELECT FilmName FROM Films<br />

The query’s first condition requires that the film must not have been released in the 1960s, or to rephrase<br />

it, the film’s year of release must not be between 1960 and 1969. This condition requires a BETWEEN<br />

operator:<br />

WHERE ( YearReleased NOT BETWEEN 1960 AND 1969 )<br />

The next condition requires that film’s name must begin with a letter in the range of P to T:<br />

WHERE ( YearReleased NOT BETWEEN 1960 AND 1969 )<br />

AND<br />

( FilmName BETWEEN ‘P’ AND ‘T’ )<br />

Putting it all together provides the following <strong>SQL</strong>:<br />

SELECT FilmName<br />

FROM Films<br />

WHERE ( YearReleased NOT BETWEEN 1960 AND 1969 )<br />

AND<br />

( FilmName BETWEEN ‘P’ AND ‘T’ )<br />

Extracting Information<br />

69

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

Saved successfully!

Ooh no, something went wrong!