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

This time, you achieve more specific results:<br />

FirstName LastName Category FilmName YearReleased<br />

Jamie Hills War The Dirty Half Dozen 1987<br />

Jamie Hills War Planet of the Japes 1967<br />

Jamie Hills Horror The Lion, the Witch, and 1977<br />

the Chest of Drawers<br />

Jamie Hills Horror Nightmare on Oak Street, Part 23 1997<br />

Jamie Hills Horror One Flew over the Crow’s Nest 1975<br />

Jamie Hills Sci-fi The Wide Brimmed Hat 2005<br />

Jamie Hills Sci-fi Soylent Yellow 1967<br />

As you created the query, you probably noticed that each time you ran the query it produced a unique<br />

set of results. That happens because each additional INNER JOIN linked to the results set created by the<br />

previous <strong>SQL</strong>. Before moving on to the section that explains the set-based nature of <strong>SQL</strong>, you should<br />

gain more familiarity with the use of brackets in MS Access.<br />

Using Brackets around Inner Joins in MS Access<br />

100<br />

You can skip over this section if you’re not using MS Access. As mentioned previously, MS Access<br />

requires brackets around joins when there’s more than one join. Each join creates a set of data, which is<br />

discussed later. Each set of data needs to be enclosed in brackets, unless there’s only one set.<br />

For example, the following statement involves only one join and therefore only one source set of data:<br />

SELECT MemberDetails.MemberId<br />

FROM MemberDetails INNER JOIN FavCategory<br />

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

However, if you then join that set of data to another table, creating a second set of data, you must<br />

enclose the first set of data inside brackets, like so:<br />

SELECT MemberDetails.MemberId<br />

FROM (MemberDetails INNER JOIN FavCategory<br />

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

INNER JOIN Category<br />

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

The following excerpt illustrates how the original join is enclosed inside its own brackets:<br />

FROM (MemberDetails INNER JOIN FavCategory<br />

ON MemberDetails.MemberId = FavCategory.MemberId)

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

Saved successfully!

Ooh no, something went wrong!