DELAPARRA
Index
Color
NL
Category: SQL

CROSS JOIN

Explained by Updated

What is CROSS JOIN?

CROSS JOIN: The Cartesian product — every row of A paired with every row of B. No ON clause. A CROSS JOIN combines every row of one table with every row of another. With three sizes and four colours, it returns twelve rows, one for each combination. That is useful when you really need all combinations. Generating product variants, building a calendar of every day for every employee, or filling a report so empty combinations show up as zero are typical cases.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about CROSS JOIN

What should you keep in mind with CROSS JOIN?

The danger is size. Two tables of 10,000 rows produce 100 million rows. An accidental cross join, often caused by forgetting the join condition in older comma-style syntax, can bring a database to its knees. If a query suddenly returns far more rows than expected, check every join for a missing ON clause first.

What does an example of CROSS JOIN look like?

SELECT s.size, c.color FROM sizes s CROSS JOIN colors c;

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.