Beginner

528. CROSS JOIN

Understand how CROSS JOIN creates every possible combination of rows from two tables.

📘 Lesson 528 of 728 ⏱ 11 min 🎯 Intermediate

A CROSS JOIN returns the Cartesian product of two tables. Every row from the first table is combined with every row from the second table.

CROSS JOINs can be useful for generating combinations but can also create very large result sets.

Generate every possible combination of products and store locations.

SQL
SELECT
    p.ProductName,
    s.StoreName
FROM Products p
CROSS JOIN Stores s;

Used for scenario generation, product-location combinations, calendar creation, and test data generation.

  • CROSS JOIN creates every possible combination.
  • It does not require an ON condition.
  • Result size can become very large.
  • It can be useful for generating combinations.
  • Use it intentionally.
What does CROSS JOIN return?

It returns every possible combination of rows from the two tables.

Why can CROSS JOIN be dangerous?

The result can grow rapidly because every row from one table is combined with every row from the other table.

Have you finished this lesson?

Introduction to SQL – All Lessons