Joining tables with the cross product

One of the tables in the sample database is fin_data, which lists the financial data for the company. Each data record has a code column that tells its department and whether it is an expense or revenue record. There are 84 rows in the fin_data table.

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 dbisql SELECT command lists all the data in the fin_code and fin_data tables:

SELECT *
FROM fin_code, fin_data

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

The cross product join is a simple starting point for understanding joins, but 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.