Tools

SQL CROSS JOIN

Share:
Article Summary

A CROSS JOIN returns every possible combination of rows from two tables.It’s called a Cartesian product – no ON clause is required. πŸ”Ή Basic Syntax πŸ”Ή Example: All Product and Region Combinations βœ… If there are 5 products and 3 regions, you get 5 Γ— 3 = 15 rows – every combination. πŸ”Ή Use Cases […]

A CROSS JOIN returns every possible combination of rows from two tables.
It’s called a Cartesian product – no ON clause is required.

πŸ”Ή Basic Syntax

SELECT *
FROM table1
CROSS JOIN table2;

πŸ”Ή Example: All Product and Region Combinations

SELECT
  p.product_name,
  r.region_name
FROM products p
CROSS JOIN regions r;

βœ… If there are 5 products and 3 regions, you get 5 Γ— 3 = 15 rows – every combination.

πŸ”Ή Use Cases

  • Generate all combinations (e.g., size Γ— color)
  • Testing and simulations
  • Matrix-style reports

⚠️ Caution

CROSS JOIN can return very large results if the tables are big. Use it carefully.

🧠 Quick Recap

Key PointExplanation
CROSS JOINReturns all combinations of rows from both tables
Output sizeMultiplies row counts (rows_A Γ— rows_B)
No ON clauseDoesn’t need a join condition
Use casesAll pairings, simulations, exhaustive comparisons

πŸ’‘ Use CROSS JOIN when you need every combination of two sets

Was this helpful?

Written by

W3buddy
W3buddy

Explore W3Buddy for in-depth guides, breaking tech news, and expert analysis on AI, cybersecurity, databases, web development, and emerging technologies.