0
0
MySQLquery~20 mins

CROSS JOIN in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cross Join Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of CROSS JOIN with two small tables

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;
MySQL
SELECT Colors.name AS Color, Shapes.name AS Shape FROM Colors CROSS JOIN Shapes;
A[{"Color": "Red", "Shape": "Square"}, {"Color": "Blue", "Shape": "Square"}]
B[{"Color": "Red", "Shape": "Circle"}, {"Color": "Blue", "Shape": "Square"}]
C[{"Color": "Red", "Shape": "Circle"}, {"Color": "Red", "Shape": "Square"}, {"Color": "Blue", "Shape": "Circle"}, {"Color": "Blue", "Shape": "Square"}]
D[{"Color": "Red", "Shape": "Circle"}, {"Color": "Blue", "Shape": "Circle"}]
Attempts:
2 left
💡 Hint

Remember, CROSS JOIN returns every combination of rows from both tables.

🧠 Conceptual
intermediate
1:30remaining
Understanding the effect of CROSS JOIN on row count

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;
A8
B15
C5
D3
Attempts:
2 left
💡 Hint

Think about how many combinations each employee can have with departments.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in CROSS JOIN query

Which option contains a syntax error in the CROSS JOIN query?

MySQL
SELECT * FROM A CROSS JOIN B;
ASELECT * FROM A CROSS JOIN B;
BSELECT * FROM A CROSSJOIN B;
CSELECT * FROM A CROSS JOINB;
DSELECT * FROM A CROSS JOIN B
Attempts:
2 left
💡 Hint

Check the spacing and keywords carefully.

🔧 Debug
advanced
2:00remaining
Why does this CROSS JOIN query return no rows?

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?

ABecause there are no matching ids between Products and Categories
BBecause CROSS JOIN requires an ON clause instead of WHERE
CBecause CROSS JOIN returns no rows when a WHERE clause is present
DBecause Products and Categories tables are empty
Attempts:
2 left
💡 Hint

Think about what the WHERE clause does after the CROSS JOIN.

optimization
expert
2:30remaining
Optimizing a CROSS JOIN with large tables

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?

ASELECT * FROM Users LEFT JOIN Events ON Users.id = Events.user_id;
BSELECT * FROM Users CROSS JOIN Events WHERE Users.id = Events.user_id;
CSELECT * FROM Users, Events WHERE Users.id = Events.user_id;
DSELECT * FROM Users INNER JOIN Events ON Users.id = Events.user_id;
Attempts:
2 left
💡 Hint

Consider how JOIN types affect performance and filtering.