About Combining Tables

A query result can include data from multiple tables. To combine data from tables, you use the Join operation from SQL.

The basic join operation

The Join operation matches rows of one table with rows of another table, based on values in those rows. For example, you can join the table titles with the table publishers. Each row in the result set will describe a title, including information about that titleÆs publisher, as shown in the following illustration:

 

Types of joins

When you join tables, the type of join that you create affects the rows that appear in the result set. You can create the following types of joins:

Joining columns

The JOIN operator matches rows by comparing values in one table with values in another. You decide which columns from each table should be matched. You have several choices:

Note also that you use multiple columns to match rows from the joined tables. For example, to find the author-publisher pairs in which the author and publisher are located in the same city, you use a join operation matching the respective state columns and the respective city columns of the two tables. You need to match both city and state because it is possible that different states could have like-named cities (e.g., Springfield, Illinois and Springfield, Massachusetts).

Join comparison operators

The JOIN operator matches rows by comparing values in one table with values in another. You can decide exactly what constitutes a match. Your choices fall into two broad categories:

Joining tables

When combining data from multiple tables, you must decide what tables to use. There are several noteworthy considerations: