Beginner

638. CROSS JOIN Row Count

Calculate and understand the number of rows produced by a CROSS JOIN.

📘 Lesson 638 of 728 ⏱ 12 min 🎯 Intermediate

A CROSS JOIN produces a number of rows equal to the row count of the first table multiplied by the row count of the second table.

Understanding result size helps prevent accidental large queries and unexpected performance problems.

If Products has 20 rows and Regions has 5 rows, a CROSS JOIN produces 100 combinations.

SQL
SELECT COUNT(*) AS CombinationCount
FROM Products p
CROSS JOIN Regions r;

Used in scenario generation, test-data creation, scheduling, and analytical matrices.

  • Result rows = rows in table A × rows in table B.
  • No matching condition is required.
  • Small tables can still produce many combinations.
  • COUNT(*) can verify the generated size.
  • Always estimate the result before using CROSS JOIN.
How is CROSS JOIN row count calculated?

Multiply the number of rows in the first table by the number of rows in the second table.

What happens if one table is empty?

The CROSS JOIN returns zero rows because there are no rows available from the empty table.

Have you finished this lesson?

Introduction to SQL – All Lessons