8. Cartesian Products

In Item 22, “Understand relational algebra and how it is implemented in SQL,” you read about Cartesian Products, which are the results of combining all rows in one table or row set with all rows in a second table or row set. Although perhaps not as common as other join types, the CROSS JOIN (which is how you create a Cartesian Product in SQL) is often a necessary input when creating SQL statements.

In this chapter we show you several real-world situations where it would not be possible to answer the underlying question without the use of a Cartesian Product. Note that we are not talking about unintentional Cartesian Products that you might produce by forgetting to include one or more columns required for a multiple-column ...

Get Effective SQL: 61 Specific Ways to Write Better SQL, First 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.