CROSS JOIN — Complete Guide
CROSS JOIN — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 25 of 100
CROSS JOIN
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Joins & Relationships
What is this?
CROSS JOIN produces every combination of rows from two tables — Cartesian product. No ON clause. Row count = left rows × right rows.
Why should you care?
Generating all size × color combos for a catalog preview, or building a date × store matrix for planning sheets.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT s.size_label, c.color_name
FROM sizes s
CROSS JOIN colors c
ORDER BY s.size_label, c.color_name;
What happened?
- If sizes has 4 rows and colors 3, you get 12 variant rows.
- Useful for scaffolding product variants before real inventory exists.
Practice next
- CREATE sizes and colors with a few rows each.
- Run CROSS JOIN; count rows = product.
- Add WHERE filter to trim unwanted pairs.
- CROSS JOIN calendar dates to stores for empty sales grid.
- Use JOIN ... ON 1=1 — same as CROSS JOIN (anti-pattern demo).
Remember
No join condition — all pairs. Great for small generator tables. Dangerous at scale without filter.
DataFlow variant matrix
Merchandising previews all size/color pairs before SKUs are created.
Outcome: Buying team sees full assortment gap early.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!