Beginning SQL

Beginning SQL Beginning SQL

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

Chapter 3 106 You should see the following results: Category MemberId Thriller 5 Thriller 10 Thriller 12 Romance 1 Romance 14 Horror 10 Horror 11 Horror 13 War 6 War 1 War 11 War 12 Sci-fi 4 Sci-fi 11 Sci-fi 13 Historical 10 Historical 12 Historical 14 Comedy 6 Comedy 4 Comedy 12 Because three new records appear in the FavCategory table with a matching record in the Category table, the results appear in the resulting join. The next stage joins the MemberDetails table to the current results set: SELECT Category.Category, MemberDetails.FirstName, MemberDetails.LastName FROM FavCategory INNER JOIN Category ON FavCategory.CategoryId = Category.CategoryId INNER JOIN MemberDetails ON FavCategory.MemberId = MemberDetails.MemberId ORDER BY MemberDetails.LastName, MemberDetails.FirstName;

Chapter 3<br />

106<br />

You should see the following results:<br />

Category MemberId<br />

Thriller 5<br />

Thriller 10<br />

Thriller 12<br />

Romance 1<br />

Romance 14<br />

Horror 10<br />

Horror 11<br />

Horror 13<br />

War 6<br />

War 1<br />

War 11<br />

War 12<br />

Sci-fi 4<br />

Sci-fi 11<br />

Sci-fi 13<br />

Historical 10<br />

Historical 12<br />

Historical 14<br />

Comedy 6<br />

Comedy 4<br />

Comedy 12<br />

Because three new records appear in the FavCategory table with a matching record in the Category<br />

table, the results appear in the resulting join.<br />

The next stage joins the MemberDetails table to the current results set:<br />

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

FROM FavCategory INNER JOIN Category<br />

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

INNER JOIN MemberDetails<br />

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

ORDER BY MemberDetails.LastName, MemberDetails.FirstName;

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

Saved successfully!

Ooh no, something went wrong!