Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

Extracting Information FirstName LastName Category FilmName YearReleased Doris Night Romance On Golden Puddle 1967 Doris Night Historical Sense and Insensitivity 2001 Doris Night Historical 15th Late Afternoon 1989 Doris Night Historical Gone with the Window Cleaner 1988 Doris Night Historical The Good, the Bad, and 1989 the Facially Challenged Susie Simons Thriller The Maltese Poodle 1947 Susie Simons Thriller Raging Bullocks 1980 Susie Simons Thriller The Life of Bob 1984 Susie Simons Horror The Lion, the Witch, and 1977 the Chest of Drawers Susie Simons Horror Nightmare on Oak Street, Part 23 1997 Susie Simons Horror One Flew over the Crow’s Nest 1975 Susie Simons Historical Sense and Insensitivity 2001 Susie Simons Historical 15th Late Afternoon 1989 Susie Simons Historical Gone with the Window Cleaner 1988 Susie Simons Historical The Good, the Bad, and 1989 the Facially Challenged Katie Smith Romance On Golden Puddle 1967 Katie Smith War The Dirty Half Dozen 1987 Katie Smith War Planet of the Japes 1967 If you want only one member’s list of films based on their favorite film categories, all you need to do is add a WHERE clause and specify their MemberId. The following SQL specifies Jamie Hills’s ID, which is 11: SELECT MemberDetails.FirstName, MemberDetails.LastName, Category.Category, FilmName, YearReleased FROM (( FavCategory INNER JOIN Category ON FavCategory.CategoryId = Category.CategoryId) INNER JOIN MemberDetails ON FavCategory.MemberId = MemberDetails.MemberId) INNER JOIN Films ON Films.CategoryId = Category.CategoryId WHERE MemberDetails.MemberId = 11 ORDER BY MemberDetails.LastName, MemberDetails.FirstName; 99

Extracting Information<br />

FirstName LastName Category FilmName YearReleased<br />

Doris Night Romance On Golden Puddle 1967<br />

Doris Night Historical Sense and Insensitivity 2001<br />

Doris Night Historical 15th Late Afternoon 1989<br />

Doris Night Historical Gone with the Window Cleaner 1988<br />

Doris Night Historical The Good, the Bad, and 1989<br />

the Facially Challenged<br />

Susie Simons Thriller The Maltese Poodle 1947<br />

Susie Simons Thriller Raging Bullocks 1980<br />

Susie Simons Thriller The Life of Bob 1984<br />

Susie Simons Horror The Lion, the Witch, and 1977<br />

the Chest of Drawers<br />

Susie Simons Horror Nightmare on Oak Street, Part 23 1997<br />

Susie Simons Horror One Flew over the Crow’s Nest 1975<br />

Susie Simons Historical Sense and Insensitivity 2001<br />

Susie Simons Historical 15th Late Afternoon 1989<br />

Susie Simons Historical Gone with the Window Cleaner 1988<br />

Susie Simons Historical The Good, the Bad, and 1989<br />

the Facially Challenged<br />

Katie Smith Romance On Golden Puddle 1967<br />

Katie Smith War The Dirty Half Dozen 1987<br />

Katie Smith War Planet of the Japes 1967<br />

If you want only one member’s list of films based on their favorite film categories, all you need to do is<br />

add a WHERE clause and specify their MemberId. The following <strong>SQL</strong> specifies Jamie Hills’s ID, which<br />

is 11:<br />

SELECT MemberDetails.FirstName, MemberDetails.LastName, Category.Category,<br />

FilmName, YearReleased<br />

FROM (( FavCategory INNER JOIN Category<br />

ON FavCategory.CategoryId = Category.CategoryId)<br />

INNER JOIN MemberDetails<br />

ON FavCategory.MemberId = MemberDetails.MemberId)<br />

INNER JOIN Films<br />

ON Films.CategoryId = Category.CategoryId<br />

WHERE MemberDetails.MemberId = 11<br />

ORDER BY MemberDetails.LastName, MemberDetails.FirstName;<br />

99

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

Saved successfully!

Ooh no, something went wrong!