Example 1
Generate every color and size combination for a product grid
2 colors × 3 sizes = 6 rows. Every color is paired with every size. Unlike INNER JOIN, no matching key is needed — CROSS JOIN intentionally produces all combinations. Adding a WHERE clause after a CROSS JOIN filters the Cartesian product and can simulate an INNER JOIN.
CREATE TABLE colors (color VARCHAR(20));
CREATE TABLE sizes (size VARCHAR(10));
INSERT INTO
colors (color)
VALUES
('Red'),
('Blue');
INSERT INTO
sizes (size)
VALUES
('S'),
('M'),
('L');SELECT
color,
size
FROM
colors
CROSS JOIN sizes
ORDER BY
color,
size;| color | size |
|---|---|
| Blue | L |
| Blue | M |
| Blue | S |
| Red | L |
| Red | M |
| Red | S |
Output is identical across all engines.