When creating a query that combines information from multiple tables, you can create joins between the tables. Joins match similar columns between the tables. This allows data from one table to be linked with associated data in another table.
To create and configure a join between two tables in your query:
Identify one column in each table that can be matched against the corresponding column in the other table.
Click and drag the column name from one table and drop it on the column in the other table.
This creates a join between the two tables.
|
Drag one of the tables away from the other so that you can distinguish between the ends of the join and the middle portion of the join.
Single-click the join to select it, and then right-click on the join and select Join Properties from the right-click menu.
This displays the Object Properties: Join screen.
Most joins are configured to link data from one table with data from another table when the values in the joined columns are equal. However, if you want to link data based on another type of comparison, you can select a different option from the Join Operator list.
Other options include:
"<>" (values are not identical)
"<" (value from left table is less than value on right table)
"<=" (value from left table is less than or equal to value on right table)
">" (value from left table is greater than value on right table)
">=" (value from left table is greater than or equal to value on right table)
By default, the join you just created is an INNER JOIN. This means that the resulting SQL statement will return only data from both tables for which a corresponding value exists in both tables. For an example of data rows returned by an INNER JOIN, click here.
However, if you want to return data from one or both tables even when only one of the two tables contains a value, you can choose other options.
To create a LEFT OUTER JOIN, select the first All from tablename check box and clear the second All from tablename check box. For an example of data rows returned by an LEFT OUTER JOIN, click here.
This returns data from the Orders table even when there is no corresponding data in the Cust table, but not vice versa.
To create a RIGHT OUTER JOIN, clear the first All from tablename check box and select the second All from tablename check box. For an example of data rows returned by an RIGHT OUTER JOIN, click here.
This returns data from the Cust table even when there is no corresponding data in the Orders table, but not vice versa.
To create a FULL OUTER JOIN, select both All from tablename check boxes. For an example of data rows returned by an FULL OUTER JOIN, click here.
This returns data from the Orders table even when there is no corresponding data in the Cust table, and it also returns data from the Cust table even when there is no corresponding data in the Orders table.
|
Click OK to apply these settings to the join.
If you selected one or both of the check boxes to include all rows from either table – creating a LEFT OUTER JOIN, RIGHT OUTER JOIN or FULL OUTER JOIN – an arrow indicating the direction of the join is displayed.
The example below displays a LEFT OUTER JOIN:
More: