SQL CROSS JOIN
Pair every row of one table with every row of another.
Syntax
FROM a CROSS JOIN b
The result has rows(a) × rows(b) rows. Useful for building grids.
Example
Query (on the shop database used in the SQL course)
SELECT c.category, s.status FROM (SELECT DISTINCT category FROM products) AS c CROSS JOIN (SELECT DISTINCT status FROM orders) AS s LIMIT 6;
Result
| category | status |
|---|---|
| Electronics | pending |
| Electronics | delivered |
| Electronics | shipped |
| Electronics | cancelled |
| Books | pending |
| Books | delivered |
6 rows
Related
Learn it step by step in the free lesson Joining Tables, with exercises that check your queries.