Examine a sample SQL query in a SAS Data Integration
Studio job to see the effects of changing the join types that are
used in the query. The sample query contains the tables and columns
that are listed in the following table:
Sample Query Data
Source Table 1: POSTALCODES
|
Source Table 2: UNITEDSTATES
|
|
|
|
|
The join
condition for the query is POSTALCODES.Name = UNITEDSTATES.Name. The
query is depicted in the following display.
Sample SQL Query in a SAS Data Integration Studio Job
Notice that the query contains an inner join and a
WHERE statement. These components are included by default when a query
is first created. The following table illustrates how the query is
affected when you run through all of the available join types in succession:
Results By Join Type
|
|
|
Implicit or Explicit Status
|
|
Combines and displays only the
rows from the first table that match rows from the second table, based
on the matching criteria that are specified in the WHERE clause.
|
50 rows: 50 matches on name column;
0 non-matches
|
|
|
Retrieves both the matching rows
and the non-matching rows from both tables.
|
59 rows: 50 matches on name column;
8 non-matches from POSTALCODES (left table); 1 non-match from UNITEDSTATES
(right table)
|
|
|
Retrieves both the matching rows
and the non-matching rows from the left table.
|
58 rows: 50 matches on name column;
8 non-matches from POSTALCODES (left table)
|
|
|
Retrieves both the matching rows
and the non-matching rows from the right table.
|
51 rows: 50 matches on name column;
1 non-match from UNITEDSTATES (right table)
|
|
|
Combines each row in the first
table with every row in the second table (creating a Cartesian product
of the tables).
|
|
|
|
Selects unique rows from both tables
together and overlays the columns. PROC SQL first concatenates and
sorts the rows from the two tables, and then eliminates any duplicate
rows. See the following display for the results of a sample union
join.
|
109 rows: 58 rows from POSTALCODES
(left table); 51 rows from UNITEDSTATES (right table)
|
|
A section
of the View Data window for a sample query that includes a union join
is depicted in the following display.
Sample Section from a View of a Union Join
Rows 45
to 51 come from the POSTALCODES table. Rows 52 to 59 come from the
UNITEDSTATES table.
These
joins are contained in the FROM clause in the SELECT statement, which
comes earlier in an SQL query than a WHERE statement. You can often
create more efficient query performance by using the proper join type
in a SELECT statement than you can by setting conditions in a WHERE
statement that comes later in the query.