Constraining the Cartesian Product

Single-row tables, however, are not the norm. Without a valid join, precisely stated and refined, a query on multiple tables with multiple rows can produce an uncontrolled display of the whole set of possible connections between the tables.

In the bookbiz database, the Cartesian product of the publishers table (3 rows) and the authors table (23 rows) shows a results display of 69 rows (3 rows × 23 rows). This result is not only excessive but downright misleading because it seems to imply that every author in the database has a relationship with every publisher in the database—which is not true at all. Getting the Cartesian product represents a failure of communication between you and your system.

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.