Left Outer Join | SQL Joins | VantageCloud Lake - Left Outer Join - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

When you perform a left outer join on the Offerings and Enrollment tables, the rows from the left table that are not returned in the result of the inner join of these two tables are returned in the outer join result and extended with nulls.

Example: Inner/Outer Table

The following example uses the explicit table names inner_table and outer_table to indicate how these terms relate to the way a simple left outer join is constructed in the FROM clause of a SELECT statement. See Inner Table and Outer Table

The example shows the semantics of inner and outer table references for a left outer join.

outer_table LEFT OUTER JOIN inner_table


Section 1 represents the inner join ∩ (intersection) of outer_table and inner_table. Section 2 represents the unmatched rows from the outer table.

The outer join result contains the matching rows from Sections 2 and 3, indicated in the diagram as Section 1, plus unmatched rows from Section 2, noted in the graphic by the more lightly shaded component of the Venn diagram.

In terms of the algebra of sets, the result is

(Table_A ∩ Table_B) + (Table_A - Table_B)

where:

Table_A ∩ Table_B is the set of matched rows from the inner join of Table_A and Table_B.

Table_A - Table_B is the set of unmatched rows from Table_A.

Example: Left Outer Join

SELECT offerings.course_no,offerings.location,enrollment.emp_no
FROM offerings
LEFT OUTER JOIN enrollment ON offerings.course_no = employee.course_no;

Result:

o.course_no o.location e.emp_no
C100 El Segundo 236
C100 El Segundo 668
C200 Dayton Null
C400 El Segundo Null

BTEQ reports represent nulls with the QUESTION MARK character.

These results show that course C100 has two enrolled employees and that courses C200 and C400 have no enrolled employees. The nulls returned by the outer join of the offerings and enrollment tables provide meaningful information.

The keyword OUTER in the FROM clause is optional, so you can also write the preceding SELECT statement as follows:

SELECT offerings.course_no,offerings.location,enrollment.emp_no
FROM offerings
LEFT JOIN enrollment ON offerings.course_no = employee.course_no;