0
0
SQLquery~20 mins

INNER JOIN with multiple conditions in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of INNER JOIN with multiple conditions
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
INNER JOIN with two conditions
Given two tables Employees and Departments, what is the result of this query?
SQL
SELECT e.EmployeeID, e.Name, d.DepartmentName
FROM Employees e
INNER JOIN Departments d
ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
A[{"EmployeeID": 2, "Name": "Bob", "DepartmentName": "Sales"}, {"EmployeeID": 3, "Name": "Charlie", "DepartmentName": "HR"}]
B[{"EmployeeID": 1, "Name": "Alice", "DepartmentName": "Sales"}, {"EmployeeID": 2, "Name": "Bob", "DepartmentName": "Sales"}]
C[{"EmployeeID": 1, "Name": "Alice", "DepartmentName": "Sales"}, {"EmployeeID": 3, "Name": "Charlie", "DepartmentName": "HR"}]
D[]
Attempts:
2 left
💡 Hint
Remember that both conditions in the ON clause must be true for a row to join.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in INNER JOIN with multiple conditions
Which option contains a syntax error in the INNER JOIN with multiple conditions?
SQL
SELECT e.EmployeeID, e.Name, d.DepartmentName
FROM Employees e
INNER JOIN Departments d
ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
ASELECT * FROM Employees e INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
BSELECT * FROM Employees e INNER JOIN Departments d ON (e.DepartmentID = d.DepartmentID AND e.Location = d.Location);
C;noitacoL.d = noitacoL.e DNA DItnemtrapeD.d = DItnemtrapeD.e NO d stnemtrapeD NIOJ RENNI e seeyolpmE MORF * TCELES
DSELECT * FROM Employees e INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID, e.Location = d.Location;
Attempts:
2 left
💡 Hint
Check the use of AND and commas in the ON clause.
optimization
advanced
2:00remaining
Optimizing INNER JOIN with multiple conditions
Which option is the most efficient way to write an INNER JOIN with multiple conditions for large tables?
ASELECT * FROM Employees e, Departments d WHERE e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
BSELECT * FROM Employees e INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
CSELECT * FROM Employees e INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID OR e.Location = d.Location;
DSELECT * FROM Employees e LEFT JOIN Departments d ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location WHERE d.DepartmentID IS NOT NULL;
Attempts:
2 left
💡 Hint
INNER JOIN with ON clause is generally more efficient than WHERE with comma joins.
🔧 Debug
advanced
2:00remaining
Why does this INNER JOIN return no rows?
Given these tables, why does this query return no rows? SELECT e.EmployeeID, d.DepartmentName FROM Employees e INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID AND e.Location = d.Location;
ABecause no rows have matching DepartmentID and Location in both tables.
BBecause the Employees table is empty.
CBecause the ON clause uses AND instead of OR.
DBecause INNER JOIN requires a WHERE clause to filter rows.
Attempts:
2 left
💡 Hint
Check if the join conditions match any rows in both tables.
🧠 Conceptual
expert
2:00remaining
Understanding INNER JOIN with multiple conditions logic
Which statement best describes how INNER JOIN with multiple conditions works?
AIt returns rows where all conditions in the ON clause are true for the joined tables.
BIt returns rows where at least one condition in the ON clause is true.
CIt returns all rows from the left table and matching rows from the right table.
DIt returns all rows from both tables regardless of conditions.
Attempts:
2 left
💡 Hint
Think about how AND works in the ON clause.