The CROSS JOIN Clause in SQL

🟢 Intermediate Level | Cartesian Product Generation

📖 Definition

A CROSS JOIN produces a Cartesian product between two database tables, pairing every row from Table A with every row from Table B. If Table A has $N$ rows and Table B has $M$ rows, the result set contains $N \times M$ rows.

🤔 Purpose

Used to generate complete matrices, product combinations (e.g. sizes $\times$ colors), date grids, and test data permutations.

🌐 Multilingual Explanations

English

A CROSS JOIN returns all possible combinations of rows from the joined tables without requiring an ON predicate.

Hindi

CROSS JOIN dono tables ki har row ko aapas me combine karke Cartesian Product (total $N \times M$ rows) banata hai.

Marathi

Dohitahi tables madhil sarv possible combinations CROSS JOIN ne tayar hotat.

Hinglish

Grid generation query: SELECT * FROM colors CROSS JOIN sizes; use karein.

📝 Syntax & Parameters

SELECT t1.column1, t2.column2
FROM table1 t1
CROSS JOIN table2 t2;

💡 Progressive Example

-- Generating all combinations of products and sizes
SELECT products.product_name, sizes.size_code
FROM products
CROSS JOIN sizes;

🖥️ Expected Output

+--------------+-----------+
| product_name | size_code |
+--------------+-----------+
| T-Shirt      | S         |
| T-Shirt      | M         |
| T-Shirt      | L         |
| Hoodie       | S         |
| Hoodie       | M         |
| Hoodie       | L         |
+--------------+-----------+