0
0
SQLquery~20 mins

Why joins are needed in SQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Join Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do we use JOINs in SQL?

Imagine you have two tables: Customers and Orders. Each order belongs to a customer. Why do we need to use a JOIN to get a list of customers with their orders?

ABecause JOINs delete duplicate rows from tables to keep data clean.
BBecause JOINs create new tables permanently to store combined data.
CBecause JOINs sort the data alphabetically in the result set.
DBecause JOINs combine rows from two or more tables based on a related column, allowing us to see connected data in one result.
Attempts:
2 left
💡 Hint

Think about how you can see information from both tables together in one list.

query_result
intermediate
2:00remaining
Output of INNER JOIN between Customers and Orders

Given these tables:

Customers:
1, Alice
2, Bob

Orders:
101, 1
102, 2
103, 1

What is the result of this query?

SELECT Customers.Name, Orders.OrderID FROM Customers INNER JOIN Orders ON Customers.ID = Orders.CustomerID;
AAlice, 101<br>Alice, 103<br>Bob, 102
BAlice, 101<br>Bob, 102<br>NULL, 103
CAlice, 101<br>Bob, 102
DAlice, 101<br>Alice, 103
Attempts:
2 left
💡 Hint

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

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this JOIN query

Which option contains a syntax error in the JOIN clause?

SELECT * FROM Customers JOIN Orders ON Customers.ID = Orders.CustomerID;
ASELECT * FROM Customers JOIN Orders ON Customers.ID = Orders.CustomerID ORDER BY;
BSELECT * FROM Customers JOIN Orders ON Customers.ID = Orders.CustomerID;
CSELECT * FROM Customers JOIN Orders Customers.ID = Orders.CustomerID;
DSELECT * FROM Customers JOIN Orders ON Customers.ID = Orders.CustomerID WHERE;
Attempts:
2 left
💡 Hint

Look for missing keywords or misplaced clauses in the JOIN syntax.

optimization
advanced
2:00remaining
Optimizing JOINs for performance

You have two large tables: Employees and Departments. You want to list employees with their department names. Which option is best to improve query speed?

AUse CROSS JOIN to combine all rows and then filter with WHERE.
BUse INNER JOIN on indexed columns and select only needed columns.
CUse LEFT JOIN without any indexes and select all columns.
DUse subqueries instead of JOINs to get department names.
Attempts:
2 left
💡 Hint

Think about how indexes and selecting fewer columns affect speed.

🔧 Debug
expert
2:00remaining
Why does this JOIN query return fewer rows than expected?

Tables:

Students: 1, John
2, Mary
3, Alex

Enrollments: 1, Math
2, Science

Query:

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

Why does Alex not appear in the result?

ABecause INNER JOIN only returns rows with matching keys in both tables, and Alex has no enrollment record.
BBecause Alex's name is misspelled in the Students table.
CBecause the query syntax is incorrect and skips some rows.
DBecause the Enrollments table has duplicate courses causing conflicts.
Attempts:
2 left
💡 Hint

Think about how INNER JOIN works when one table has missing matching rows.