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 3<br />

94<br />

❑ Category<br />

❑ FavCategory<br />

Now you need to work out how to link them all up. The results you’re after comprise a list of films in<br />

each member’s favorite category, and the FavCategory table is central to the results, so the first step is to<br />

link that table. You don’t need to use a WHERE clause in this <strong>SQL</strong> because you want all the results. Begin<br />

with a simple SELECT statement to return all the results from the FavCategory table:<br />

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

FROM FavCategory;<br />

That’s simple enough and returns the following results:<br />

CategoryId MemberId<br />

1 3<br />

1 5<br />

1 10<br />

2 1<br />

2 3<br />

3 3<br />

4 6<br />

4 1<br />

3 10<br />

5 3<br />

5 4<br />

6 10<br />

4 11<br />

3 11<br />

5 11<br />

1 12<br />

4 12<br />

6 12<br />

3 13<br />

5 13<br />

2 14<br />

6 14<br />

1 3

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

Saved successfully!

Ooh no, something went wrong!