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.

Category MemberId<br />

Thriller 5<br />

Thriller 10<br />

Romance 1<br />

War 6<br />

War 1<br />

Horror 10<br />

Sci-fi 4<br />

Historical 10<br />

War 11<br />

Horror 11<br />

Sci-fi 11<br />

Thriller 12<br />

War 12<br />

Historical 12<br />

Horror 13<br />

Sci-fi 13<br />

Romance 14<br />

Historical 14<br />

Notice the difference? That’s right, there is no difference; even though you added an extra record to the<br />

Category table, the addition doesn’t affect the results because no records exist in the FavCategory results<br />

set that match the new CategoryId of 7. Now add a few new favorite categories to the FavCategory table<br />

that have a CategoryId of 7:<br />

INSERT INTO FavCategory (CategoryId, MemberId)<br />

VALUES (7, 6);<br />

INSERT INTO FavCategory (CategoryId, MemberId)<br />

VALUES (7, 4);<br />

INSERT INTO FavCategory (CategoryId, MemberId)<br />

VALUES (7, 12);<br />

Execute the <strong>SQL</strong> and then rerun the SELECT query:<br />

SELECT Category.Category, FavCategory.MemberId<br />

FROM FavCategory INNER JOIN Category<br />

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

Extracting Information<br />

105

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

Saved successfully!

Ooh no, something went wrong!