The CROSS JOIN returns the Cartesian product of two tables. Each row from the first table is combined with every row from the second table. It essentially creates every possible pairing between the two datasets.
ON or USING clause.
// Basic syntax of CROSS JOIN
SELECT column1, column2
FROM table1
CROSS JOIN table2;
// Sample students table data
id | name
1 | Alice
2 | Bob
// Sample courses table data
id | course
1 | Math
2 | Science
// Combine each student with every course
SELECT students.name, courses.course
FROM students
CROSS JOIN courses;
// Resulting Cartesian product (4 rows total)
Alice | Math
Alice | Science
Bob | Math
Bob | Science
This grid demonstrates a CROSS JOIN between Users (A, B) and Actions (Login, Logout, Edit):
SELECT * FROM table1, table2 is often treated as a CROSS JOIN in many SQL dialects.WHERE clause to a CROSS JOIN to turn it into an INNER JOIN.colors (Red, Blue) and sizes (S, M, L) tables and join them.