What is Cross Join?
Colors Table
| color |
|---|
| Red |
| Blue |
2 rows
Sizes Table
| size |
|---|
| Small |
| Large |
2 rows
Cross Join combines EVERY row from first table with EVERY row from second table.
Simple analogy: If you have 3 shirts and 2 pants, Cross Join shows all 6 combinations.
Basic Example
Colors Table
| color |
|---|
| Red |
| Blue |
2 rows
Sizes Table
| size |
|---|
| Small |
| Large |
2 rows
Colors: Red, Blue Sizes: Small, Large
SELECT colors.color, sizes.size
FROM colors
CROSS JOIN sizes;Result: 4 combinations
- Red - Small
- Red - Large
- Blue - Small
- Blue - Large
When to Use
Colors Table
| color |
|---|
| Red |
| Blue |
2 rows
Sizes Table
| size |
|---|
| Small |
| Large |
2 rows
Rarely used! Creates many rows quickly.
Use for: Generating all possible combinations (like product variants).
Warning
Colors Table
| color |
|---|
| Red |
| Blue |
2 rows
Sizes Table
| size |
|---|
| Small |
| Large |
2 rows
If table1 has 100 rows and table2 has 100 rows, Cross Join creates 10,000 rows!
What Comes Next
Colors Table
| color |
|---|
| Red |
| Blue |
2 rows
Sizes Table
| size |
|---|
| Small |
| Large |
2 rows
Congratulations! You learned all JOIN types.