Beginning SQL
Beginning SQL Beginning SQL
Extracting Information FirstName LastName Category FilmName YearReleased Doris Night Romance On Golden Puddle 1967 Doris Night Historical Sense and Insensitivity 2001 Doris Night Historical 15th Late Afternoon 1989 Doris Night Historical Gone with the Window Cleaner 1988 Doris Night Historical The Good, the Bad, and 1989 the Facially Challenged Susie Simons Thriller The Maltese Poodle 1947 Susie Simons Thriller Raging Bullocks 1980 Susie Simons Thriller The Life of Bob 1984 Susie Simons Horror The Lion, the Witch, and 1977 the Chest of Drawers Susie Simons Horror Nightmare on Oak Street, Part 23 1997 Susie Simons Horror One Flew over the Crow’s Nest 1975 Susie Simons Historical Sense and Insensitivity 2001 Susie Simons Historical 15th Late Afternoon 1989 Susie Simons Historical Gone with the Window Cleaner 1988 Susie Simons Historical The Good, the Bad, and 1989 the Facially Challenged Katie Smith Romance On Golden Puddle 1967 Katie Smith War The Dirty Half Dozen 1987 Katie Smith War Planet of the Japes 1967 If you want only one member’s list of films based on their favorite film categories, all you need to do is add a WHERE clause and specify their MemberId. The following SQL specifies Jamie Hills’s ID, which is 11: SELECT MemberDetails.FirstName, MemberDetails.LastName, Category.Category, FilmName, YearReleased FROM (( FavCategory INNER JOIN Category ON FavCategory.CategoryId = Category.CategoryId) INNER JOIN MemberDetails ON FavCategory.MemberId = MemberDetails.MemberId) INNER JOIN Films ON Films.CategoryId = Category.CategoryId WHERE MemberDetails.MemberId = 11 ORDER BY MemberDetails.LastName, MemberDetails.FirstName; 99
- Page 188: Chapter 3 It’s as simple as that!
- Page 192: Chapter 3 76 YearReleased 1947 1967
- Page 196: Chapter 3 78 FilmName Rating Gone w
- Page 200: Chapter 3 2. Add a WHERE clause to
- Page 204: Chapter 3 Executing this SQL provid
- Page 208: Chapter 3 84 FullName First name is
- Page 212: Chapter 3 86 FullName First name is
- Page 216: Chapter 3 Even though DateOfBirth i
- Page 220: Chapter 3 Member Name The member is
- Page 224: Chapter 3 92 The preceding SQL prod
- Page 228: Chapter 3 94 ❑ Category ❑ FavCa
- Page 232: Chapter 3 96 You’re one step furt
- Page 236: Chapter 3 98 FirstName LastName Cat
- Page 242: If you take this further and join t
- Page 246: SELECT * FROM FavCategory Figure 3-
- Page 250: Category MemberId Thriller 5 Thrill
- Page 254: Remember to add brackets around the
- Page 258: surprisingly, the MemberDetails tab
- Page 262: LocationId 2 2 2 2 1 1 1 Figure 3-6
- Page 266: includes that record. You should al
- Page 270: FirstName LastName DateOfBirth Jenn
- Page 274: 4 Advanced Database Design This cha
- Page 278: Date of Date Meeting Did Member Nam
- Page 282: Now the tables are in second normal
- Page 286: After changing the database so that
Extracting Information<br />
FirstName LastName Category FilmName YearReleased<br />
Doris Night Romance On Golden Puddle 1967<br />
Doris Night Historical Sense and Insensitivity 2001<br />
Doris Night Historical 15th Late Afternoon 1989<br />
Doris Night Historical Gone with the Window Cleaner 1988<br />
Doris Night Historical The Good, the Bad, and 1989<br />
the Facially Challenged<br />
Susie Simons Thriller The Maltese Poodle 1947<br />
Susie Simons Thriller Raging Bullocks 1980<br />
Susie Simons Thriller The Life of Bob 1984<br />
Susie Simons Horror The Lion, the Witch, and 1977<br />
the Chest of Drawers<br />
Susie Simons Horror Nightmare on Oak Street, Part 23 1997<br />
Susie Simons Horror One Flew over the Crow’s Nest 1975<br />
Susie Simons Historical Sense and Insensitivity 2001<br />
Susie Simons Historical 15th Late Afternoon 1989<br />
Susie Simons Historical Gone with the Window Cleaner 1988<br />
Susie Simons Historical The Good, the Bad, and 1989<br />
the Facially Challenged<br />
Katie Smith Romance On Golden Puddle 1967<br />
Katie Smith War The Dirty Half Dozen 1987<br />
Katie Smith War Planet of the Japes 1967<br />
If you want only one member’s list of films based on their favorite film categories, all you need to do is<br />
add a WHERE clause and specify their MemberId. The following <strong>SQL</strong> specifies Jamie Hills’s ID, which<br />
is 11:<br />
SELECT MemberDetails.FirstName, MemberDetails.LastName, Category.Category,<br />
FilmName, YearReleased<br />
FROM (( FavCategory INNER JOIN Category<br />
ON FavCategory.CategoryId = Category.CategoryId)<br />
INNER JOIN MemberDetails<br />
ON FavCategory.MemberId = MemberDetails.MemberId)<br />
INNER JOIN Films<br />
ON Films.CategoryId = Category.CategoryId<br />
WHERE MemberDetails.MemberId = 11<br />
ORDER BY MemberDetails.LastName, MemberDetails.FirstName;<br />
99