Chapter 7. Selecting Data from Different Tables
In Chapter 3, you learned how to use inner joins to create results sets formed from more than one table. In this chapter, to use the words of Chef Emeril, you take it up a notch and look at how you can deal with more complex problems using more sophisticated inner joins, and you also something you've not yet encountered: outer joins. Ultimately, this chapter is all about finding a way to get the data you need to answer a question, and you can expect to see lots of practical examples in this chapter.
Joins Revisited
In Chapter 3, you learned about inner joins and how they enable you to retrieve related data from different tables and display that data in one results set.
Remember, an inner join consists of the INNER JOIN
keyword, which specifies which two tables are to be joined. After the INNER JOIN
keyword, you specify an ON
clause, which identifies the condition that must be true for a row from each table to be included in the final joined results. The basic syntax of an inner join is as follows:
name_of_table_on_left INNER JOIN name_of_table_on_right ON condition
For example, the Attendance table doesn't contain the name and address of each person attending a meeting; rather, it contains only the MemberId. However, the MemberDetails table contains matching MemberIds as well as members' full details. So if you want to produce results that contain a meeting date and the name of the member attending, you'd have to create a SELECT
statement ...
Get Beginning SQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.