Given two tables Colors and Shapes:
Colors:
id | name
1 | Red
2 | Blue
Shapes:
id | name
1 | Circle
2 | Square
What is the output of this query?
SELECT Colors.name AS Color, Shapes.name AS Shape FROM Colors CROSS JOIN Shapes;
SELECT Colors.name AS Color, Shapes.name AS Shape FROM Colors CROSS JOIN Shapes;
Remember, CROSS JOIN returns every combination of rows from both tables.
The CROSS JOIN produces all possible pairs between rows of Colors and Shapes. Since Colors has 2 rows and Shapes has 2 rows, the result has 2 x 2 = 4 rows.
Table Employees has 5 rows and table Departments has 3 rows.
What will be the number of rows returned by the query:
SELECT * FROM Employees CROSS JOIN Departments;
Think about how many combinations each employee can have with departments.
CROSS JOIN returns every combination of rows from both tables. So total rows = 5 employees * 3 departments = 15 rows.
Which option contains a syntax error in the CROSS JOIN query?
SELECT * FROM A CROSS JOIN B;
Check the spacing and keywords carefully.
The keyword CROSS JOIN must be two separate words. Options B and C have invalid syntax because 'CROSSJOIN' and 'JOINB' are not valid keywords.
Given tables Products and Categories, the query below returns zero rows:
SELECT * FROM Products CROSS JOIN Categories WHERE Products.id = Categories.id;
Why does this happen?
Think about what the WHERE clause does after the CROSS JOIN.
The CROSS JOIN produces all combinations, but the WHERE clause filters rows where Products.id equals Categories.id. If no ids match, no rows remain.
You have two large tables, Users (100,000 rows) and Events (50,000 rows). You want to find all pairs where Users.id = Events.user_id.
Which query is the most efficient?
Consider how JOIN types affect performance and filtering.
INNER JOIN with ON clause directly joins matching rows efficiently. CROSS JOIN with WHERE creates all combinations first, which is costly.