This query is an inner join that helps to explain the example outer join queries and their results. The query starts with the same customer rows found in “Single Table Cardinality Estimate” on page 266, but then matches them with revenue rows for the month of July, 1997.
SELECT c.custnum, b.monthly_revenue
FROM sampdb.customer AS c, sampdb2.revenue AS b
WHERE c.custnum = b.custnum
AND c.district = 'K'
AND b.data_year_month = 199707
AND (c.service_type = 'ABC'
OR c.service_type = 'XYZ')
ORDER BY 1;
The query returns 13,010 rows.
Note that all customer table rows are matched by a monthly_revenue table row.