Part 66: CROSS JOIN: Cartesian Products & Matrix Generation
A CROSS JOIN produces the mathematical Cartesian product: every row of Table A is paired with every row of Table B (N × M rows).
1. Generating Product SKU Matrix
-- Combine all colors with all sizes:
SELECT c.color_name, s.size_name
FROM colors c
CROSS JOIN sizes s;
If there are 5 colors and 4 sizes, it generates exactly 20 SKU combinations.
Key Takeaways
CROSS JOINcreates all permutations.- Ensure input tables are small to prevent generating billions of rows!
In Part 67, we will master SELF JOIN: Hierarchical and Tree Data!

