Challenge - 5 Problems
INNER JOIN Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of INNER JOIN with matching keys
Given two tables Employees and Departments, what is the output of the following query?
Assume:
Employees: (id:1, name:'Alice', department_id:10), (id:2, name:'Bob', department_id:20), (id:3, name:'Charlie', department_id:30)
Departments: (id:10, department_name:'HR'), (id:20, department_name:'Finance')
SELECT Employees.name, Departments.department_name FROM Employees INNER JOIN Departments ON Employees.department_id = Departments.id;
Assume:
Employees: (id:1, name:'Alice', department_id:10), (id:2, name:'Bob', department_id:20), (id:3, name:'Charlie', department_id:30)
Departments: (id:10, department_name:'HR'), (id:20, department_name:'Finance')
PostgreSQL
SELECT Employees.name, Departments.department_name FROM Employees INNER JOIN Departments ON Employees.department_id = Departments.id;
Attempts:
2 left
💡 Hint
INNER JOIN returns rows where the join condition matches in both tables.
✗ Incorrect
The INNER JOIN returns only rows where Employees.department_id matches Departments.id. Charlie's department_id 30 has no matching department, so he is excluded.
🧠 Conceptual
intermediate1:30remaining
Understanding INNER JOIN behavior
Which statement best describes the behavior of an INNER JOIN between two tables?
Attempts:
2 left
💡 Hint
Think about which rows appear when both tables have matching keys.
✗ Incorrect
INNER JOIN returns only rows where the join condition matches in both tables, excluding unmatched rows.
📝 Syntax
advanced1:30remaining
Identify the syntax error in INNER JOIN query
Which option contains a syntax error in the INNER JOIN query?
PostgreSQL
SELECT e.name, d.department_name FROM Employees e INNER JOIN Departments d ON e.department_id = d.id;
Attempts:
2 left
💡 Hint
INNER JOIN requires ON clause for join condition, not WHERE.
✗ Incorrect
Option C uses WHERE instead of ON for the join condition, causing syntax error.
❓ optimization
advanced2:00remaining
Optimizing INNER JOIN performance
Which option is the best way to optimize INNER JOIN performance on large tables?
Attempts:
2 left
💡 Hint
Indexes help the database find matching rows faster.
✗ Incorrect
Adding indexes on join columns speeds up matching rows lookup, improving INNER JOIN performance.
🔧 Debug
expert2:30remaining
Diagnose unexpected INNER JOIN result
A query uses INNER JOIN between tables Orders and Customers on Customers.id = Orders.customer_id. The result is empty, but both tables have data. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check if the join columns actually match and have compatible data types.
✗ Incorrect
If join columns do not match or have incompatible types, no rows join and result is empty.