CROSS JOINs

A CROSS JOIN generates a Cartesian product of the tables specified in the JOIN operation. In other words, the result set of a CROSS JOIN operation contains every possible combination of rows of the tables involved in the query. In particular, if there are n rows in the first table and m rows in the second table, the result set will have n*m rows.

These are the two possible ways to specify a CROSS JOIN operation:

SELECT * FROM Table1, Table2
SELECT * FROM Table1 CROSS JOIN Table2

Listing 5.18 shows an example that generates a Cartesian product using CROSS JOIN. The tables involved in the CROSS JOIN have 7 and 8 rows, respectively, and the result set has 56 rows (7*8).

Code Listing 5.18. Using CROSS JOIN to Generate a Cartesian Product ...

Get Microsoft® SQL Server™ 2000 Programming by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.