0
0
MySQLquery~20 mins

INNER JOIN in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
INNER JOIN Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this INNER JOIN query?

Consider two tables: Employees and Departments.

Employees has columns: EmpID, Name, DeptID.

Departments has columns: DeptID, DeptName.

What rows will this query return?

MySQL
SELECT Employees.Name, Departments.DeptName FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
A[{"Name": "Alice", "DeptName": "HR"}, {"Name": "Bob", "DeptName": "IT"}]
B[{"Name": "Alice", "DeptName": "HR"}, {"Name": "Bob", "DeptName": "IT"}, {"Name": "Charlie", "DeptName": null}]
C[{"Name": "Alice", "DeptName": "HR"}]
D[]
Attempts:
2 left
💡 Hint

INNER JOIN returns rows where the join condition matches in both tables.

🧠 Conceptual
intermediate
1:30remaining
What does INNER JOIN do in SQL?

Choose the best description of what an INNER JOIN does.

AReturns all rows from the left table, and matching rows from the right table or NULL if no match.
BReturns only rows where there is a match in both tables based on the join condition.
CReturns all rows from both tables, combining all possible pairs.
DReturns all rows from the right table, and matching rows from the left table or NULL if no match.
Attempts:
2 left
💡 Hint

Think about which rows appear when both tables have matching values.

📝 Syntax
advanced
2:00remaining
Which query correctly uses INNER JOIN syntax?

Identify the query that will run without syntax errors and perform an INNER JOIN between Orders and Customers on CustomerID.

ASELECT * FROM Orders JOIN Customers WHERE Orders.CustomerID = Customers.CustomerID;
BSELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID == Customers.CustomerID;
CSELECT * FROM Orders INNER JOIN Customers USING (CustomerID);
DSELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
Attempts:
2 left
💡 Hint

Check the correct JOIN syntax and operator for equality in SQL.

optimization
advanced
2:30remaining
How to optimize INNER JOIN performance on large tables?

You have two large tables joined by DeptID. Which option best improves INNER JOIN query speed?

AAdd an index on the <code>DeptID</code> column in both tables.
BUse SELECT * to get all columns instead of specifying needed columns.
CUse a subquery instead of INNER JOIN.
DRemove the ON clause and join without conditions.
Attempts:
2 left
💡 Hint

Indexes help databases find matching rows faster.

🔧 Debug
expert
3:00remaining
Why does this INNER JOIN query return zero rows?

Given tables Students and Enrollments, this query returns no rows:

SELECT Students.Name, Enrollments.Course FROM Students INNER JOIN Enrollments ON Students.ID = Enrollments.StudentID;

What is the most likely reason?

AINNER JOIN always returns zero rows if tables have different column names.
BThe query syntax is incorrect and causes an error.
CThere are no matching values between <code>Students.ID</code> and <code>Enrollments.StudentID</code>.
DThe SELECT clause is missing a GROUP BY statement.
Attempts:
2 left
💡 Hint

Think about what INNER JOIN requires to return rows.