Challenge - 5 Problems
Master of Joining Multiple Tables
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of joining three tables with INNER JOIN
Given the tables Employees, Departments, and Locations, what is the output of the following SQL query?
SELECT e.name, d.department_name, l.city FROM Employees e INNER JOIN Departments d ON e.department_id = d.id INNER JOIN Locations l ON d.location_id = l.id ORDER BY e.name;
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department_id INT); CREATE TABLE Departments (id INT, department_name VARCHAR(50), location_id INT); CREATE TABLE Locations (id INT, city VARCHAR(50)); INSERT INTO Employees VALUES (1, 'Alice', 10), (2, 'Bob', 20), (3, 'Charlie', 10); INSERT INTO Departments VALUES (10, 'Sales', 100), (20, 'Engineering', 200); INSERT INTO Locations VALUES (100, 'New York'), (200, 'San Francisco');
Attempts:
2 left
💡 Hint
Think about how INNER JOIN works: it only includes rows where the join condition matches in all tables.
✗ Incorrect
The query joins Employees to Departments on department_id, then Departments to Locations on location_id. All employees have matching departments and locations, so all three employees appear with their correct department and city.
📝 Syntax
intermediate1:30remaining
Identify the syntax error in joining three tables
Which option contains a syntax error when joining three tables
Orders, Customers, and Products to get order details?SQL
SELECT o.order_id, c.customer_name, p.product_name FROM Orders o JOIN Customers c ON o.customer_id = c.id JOIN Products p ON o.product_id = p.id;
Attempts:
2 left
💡 Hint
Check the JOIN syntax carefully, especially the ON clause.
✗ Incorrect
Option B is missing the ON keyword before the join condition for Products, causing a syntax error.
❓ optimization
advanced2:30remaining
Optimizing a query joining four tables
You have four tables:
Sales, Customers, Products, and Stores. Which query is the most efficient to get sales details including customer name, product name, and store location?Attempts:
2 left
💡 Hint
Consider the clarity and performance of JOIN syntax versus older comma joins and CROSS JOINs.
✗ Incorrect
Option C uses explicit INNER JOINs which are clearer and often optimized better by SQL engines. Option C uses old-style joins which can be less efficient. Option C uses LEFT JOINs which may return extra rows if no matches exist. Option C uses CROSS JOINs which produce large intermediate results.
🧠 Conceptual
advanced1:30remaining
Understanding join types with three tables
You join three tables:
A, B, and C. If you want to keep all rows from A even if there are no matching rows in B or C, which join type should you use?Attempts:
2 left
💡 Hint
Think about which join keeps all rows from the left table regardless of matches.
✗ Incorrect
LEFT JOIN keeps all rows from the left table (A), even if there are no matches in the right tables (B and C). INNER JOIN would exclude unmatched rows.
🔧 Debug
expert2:30remaining
Debugging incorrect results from joining three tables
You run this query joining three tables but get fewer rows than expected:
What is the most likely reason for missing rows?
SELECT e.name, d.department_name, p.project_name FROM Employees e JOIN Departments d ON e.department_id = d.id JOIN Projects p ON e.id = p.employee_id WHERE d.location = 'New York';
What is the most likely reason for missing rows?
Attempts:
2 left
💡 Hint
Consider how INNER JOIN behaves when there is no matching row in the joined table.
✗ Incorrect
INNER JOIN only returns rows where matching rows exist in all joined tables. Employees without projects are excluded, causing fewer rows.