Introduction
A CROSS JOIN combines every row from one table with every row from another table, creating all possible pairs. It helps when you want to see all combinations of two sets of data.
Jump into concepts and practice - no test required
SELECT * FROM table1 CROSS JOIN table2;
SELECT * FROM fruits CROSS JOIN colors;
SELECT employees.name, departments.name FROM employees CROSS JOIN departments;
CREATE TABLE fruits (name VARCHAR(10)); INSERT INTO fruits VALUES ('Apple'), ('Banana'); CREATE TABLE colors (name VARCHAR(10)); INSERT INTO colors VALUES ('Red'), ('Yellow'); SELECT fruits.name AS fruit, colors.name AS color FROM fruits CROSS JOIN colors;
CROSS JOIN do in SQL?Employees and Departments?Colors with rows: Red, BlueShapes with rows: Circle, Square, TriangleSELECT Colors.color, Shapes.shape FROM Colors CROSS JOIN Shapes;SELECT * FROM A CROSS JOIN B WHERE A.id = B.id;Products with 4 rows and Colors with 5 rows.