Learn SQL Lesson

CROSS JOIN for All Combinations

`CROSS JOIN` returns every possible combination of rows from both tables.

If one table has 4 rows and the other has 2, the result has 8 rows.

SELECT d.name AS department_name, m.day_name
FROM departments AS d
CROSS JOIN meeting_days AS m

`CROSS JOIN` is useful for generating schedules, calendars, test cases, and other complete combinations. Be careful though: the result size grows very quickly.

Practice challenge

Create every department/day combination. Return department_name and day_name, ordered by department_name and day_name.

Open interactive editor