Example 4: Outer Join, the Correct Answer - Teradata Database

SQL Data Manipulation Language

Product
Teradata Database
Release Number
15.10
Language
English (United States)
Last Update
2018-10-06
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata® Database

Finally, we have the correct answer. This example is an outer join that provides the desired answer to the original business question.

     SELECT c.custnum, b.monthly_revenue
     FROM sampdb.customer AS c
     LEFT OUTER JOIN sampdb2.revenue AS b ON c.custnum = b.custnum
     AND   b.data_year_month = 199707
     WHERE c.district ='K'
     AND  (c.service_type = 'ABC' 
     OR    c.service_type = 'XYZ')
     ORDER BY 1;

This query returns 18,034 rows.