Joining tables with the cross product

One of the tables in the sample database is FinancialData, which lists the financial data for the company. Each data record has a code column that identifies its department and whether it is an expense or revenue record.

You can get information from two tables at the same time by listing both tables, separated by a comma, in the FROM clause of a SELECT query.

Example

The following SELECT command lists all the data in the FinancialCodes and FinancialData tables:

SELECT *
FROM FinancialCodes, FinancialData

The results of this query, displayed in the Interactive SQL data window, match every row in the FinancialCodes table with every row in the FinancialData table.This join is called a full cross product, also known as a cartesian product. Each row consists of all columns from the FinancialCodes table followed by all columns from the FinancialData table.

The cross product join is a simple starting point for understanding joins, but it is not very useful in itself. Subsequent sections in this chapter tell how to construct more selective joins, which you can think of as applying restrictions to the cross product table.