Challenge - 5 Problems
Cross Join Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of CROSS JOIN with two small tables
Given two tables Colors and Shapes with the following rows:
Colors:
id | name
1 | Red
2 | Blue
Shapes:
id | name
1 | Circle
2 | Square
What is the output of the query:
Colors:
id | name
1 | Red
2 | Blue
Shapes:
id | name
1 | Circle
2 | Square
What is the output of the query:
SELECT Colors.name AS color, Shapes.name AS shape FROM Colors CROSS JOIN Shapes ORDER BY color, shape;
Attempts:
2 left
💡 Hint
Remember that CROSS JOIN pairs every row from the first table with every row from the second table.
✗ Incorrect
CROSS JOIN produces all combinations of rows from both tables. Since we order by color then shape, Blue rows come before Red rows alphabetically, so Blue pairs appear first.
🧠 Conceptual
intermediate1:00remaining
Understanding row count after CROSS JOIN
If table A has 5 rows and table B has 3 rows, how many rows will the result have after performing a CROSS JOIN between A and B?
Attempts:
2 left
💡 Hint
Think about how many pairs you can make by combining each row from A with each row from B.
✗ Incorrect
CROSS JOIN pairs every row from A with every row from B, so total rows = 5 * 3 = 15.
📝 Syntax
advanced1:30remaining
Identify the syntax error in CROSS JOIN query
Which of the following queries will cause a syntax error in PostgreSQL?
Attempts:
2 left
💡 Hint
Check if the CROSS JOIN clause is complete with both table names.
✗ Incorrect
Option A is missing the second table name after CROSS JOIN, causing a syntax error. Option A is valid syntax but the ON clause is ignored in CROSS JOIN, so no error. Option A uses implicit join syntax and is valid.
❓ optimization
advanced2:00remaining
Performance impact of CROSS JOIN on large tables
You have two large tables: Employees with 10,000 rows and Departments with 100 rows. You run a CROSS JOIN between them without any filtering. What is the main performance concern?
Attempts:
2 left
💡 Hint
Think about how many combinations are created by pairing every row from both tables.
✗ Incorrect
CROSS JOIN returns the Cartesian product, so 10,000 * 100 = 1,000,000 rows. This large result can cause high resource usage and slow performance.
🔧 Debug
expert2:30remaining
Why does this CROSS JOIN query return fewer rows than expected?
You have two tables:
Authors: 4 rows
Books: 5 rows
You run this query:
But the result has only 5 rows. Why?
Authors: 4 rows
Books: 5 rows
You run this query:
SELECT * FROM Authors CROSS JOIN Books WHERE Authors.id = Books.author_id;
But the result has only 5 rows. Why?
Attempts:
2 left
💡 Hint
Consider how WHERE filters affect the Cartesian product result.
✗ Incorrect
The CROSS JOIN creates all combinations (4*5=20 rows), but the WHERE clause keeps only rows where Authors.id matches Books.author_id, resulting in 5 rows.