Database Reference
In-Depth Information
Figure 10.8
A Cross-Join
Between the
SONG and
MUSICCD Tables.
table. The Cartesian product retrieves all music CDs with every song
regardless of whether a CD contains the song or not. The SONG table has
118 rows and the MUSICCD table has 13 rows. The resulting row count is
1,534 rows. This is because 118 Songs multiplied by 13 CDs gives us 1,534
combinations. Figure 10.8 shows the result of the following query:
SELECT S.TITLE, M.TITLE FROM SONG S, MUSICCD M;
Row counts selected can be verified with the following queries. The
third query contains a subquery (see Chapter 12) and counts the number of
rows returned by the cross-join.
SELECT COUNT(*) FROM SONG;
SELECT COUNT(*) FROM MUSICCD;
SELECT COUNT(*) FROM
(SELECT S.TITLE, M.TITLE FROM SONG S, MUSICCD M);
MUSICCD has 13 rows.
SONG has 118 rows.
The cross-join has 1,534 (13 * 118) rows.
This particular cross-join is typical. Most cross-joins are created in error.
The MUSICCD and SONG tables should have been related to one
another with the MUSICCD_ID column through the CDTRACK table.
 
Search WWH ::




Custom Search