Solve “Deduplicate events with ROW_NUMBER”

Free. Runs in your browser, no install.

SQL · Basics & Joins

What is CROSS JOIN?

Easycross joincartesian product

Interview question

What is CROSS JOIN?

How to answer

The short answer

A CROSS JOIN creates every possible combination of rows.

If:

  • Table A = 100 rows
  • Table B = 50 rows

Result:

Output
100 × 50 = 5,000 rows

Example:

SQL
SELECT *
FROM products
CROSS JOIN colors;

If there are 100 products and 5 colors, you get 500 combinations.

Use cases

  • Generating combinations
  • Calendar/date combinations
  • Test data
  • Product/option combinations

Watch out: CROSS JOIN can explode into a huge result.

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill