Beginner

405. CROSS JOIN

Learn how CROSS JOIN creates every possible combination between two tables.

📘 Lesson 405 of 728 ⏱ 11 min 🎯 Intermediate

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

Understanding CROSS JOIN is important because an unintended Cartesian product can create extremely large result sets.

Generate every combination of available products and store locations.

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

CROSS JOIN can be useful for scenario generation, scheduling combinations, product-location analysis, and test data creation.

  • CROSS JOIN creates every possible combination.
  • It does not require an ON condition.
  • The result can become very large.
  • It is also called a Cartesian product.
  • Use it carefully with large tables.
What does CROSS JOIN produce?

It produces the Cartesian product by combining every row from the first table with every row from the second table.

Does CROSS JOIN require an ON condition?

No. CROSS JOIN does not require a join condition.

Have you finished this lesson?

Introduction to SQL – All Lessons