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.

That’s all well and good, but so far your results are only numbers; you’re after the category’s name. To<br />

get the category’s name, you need to link to the Category table via the CategoryId column, which links<br />

both tables. To link them, use an INNER JOIN:<br />

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

FROM FavCategory INNER JOIN Category<br />

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

The <strong>SQL</strong> produces the following results:<br />

Category MemberId<br />

Thriller 3<br />

Thriller 5<br />

Thriller 10<br />

Thriller 3<br />

Romance 1<br />

Romance 3<br />

Horror 3<br />

War 6<br />

War 1<br />

Horror 10<br />

Sci-fi 3<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 />

Extracting Information<br />

95

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

Saved successfully!

Ooh no, something went wrong!