20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8<br />

246<br />

SELECT FirstName, LastName, YEAR(DateOfBirth)<br />

FROM MemberDetails<br />

WHERE YEAR(DateOfBirth) = ANY (SELECT YearReleased FROM Films);<br />

The WHERE clause specifies that YEAR(DateOfBirth) must equal any one of the values returned by the<br />

subquery (SELECT YearReleased FROM Films). This subquery returns the following values, which<br />

you may remember from an earlier example:<br />

YearReleased<br />

1987<br />

1967<br />

1977<br />

1997<br />

2005<br />

2001<br />

1967<br />

1947<br />

1975<br />

1980<br />

1984<br />

1988<br />

1989<br />

1989<br />

1967<br />

If YEAR(DateOfBirth) equals any one of these values, then the condition returns true and the WHERE<br />

clause allows the record into the final results. The final results of the query are as follows:<br />

FirstName LastName YEAR(DateOfBirth)<br />

Katie Smith 1977<br />

Steve Gee 1967<br />

Doris Night 1997<br />

Seem familiar? Yup, that’s right, the results from = ANY are the same as using the IN operator:<br />

SELECT FirstName, LastName, YEAR(DateOfBirth)<br />

FROM MemberDetails<br />

WHERE YEAR(DateOfBirth) IN (SELECT YearReleased FROM Films);

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

Saved successfully!

Ooh no, something went wrong!