Challenge - 5 Problems
IN List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of WHERE with IN list filtering
Given the table Employees with columns
id, name, and department, what is the output of this query?SELECT name FROM Employees WHERE department IN ('Sales', 'Marketing');SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department VARCHAR(50)); INSERT INTO Employees VALUES (1, 'Alice', 'Sales'), (2, 'Bob', 'Engineering'), (3, 'Charlie', 'Marketing'), (4, 'Diana', 'HR');
Attempts:
2 left
💡 Hint
Look for employees whose department is either 'Sales' or 'Marketing'.
✗ Incorrect
The WHERE clause filters rows where the department is in the list ('Sales', 'Marketing'). Only Alice (Sales) and Charlie (Marketing) match.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in WHERE with IN list
Which option contains a syntax error in the use of the IN list in the WHERE clause?
SQL
SELECT * FROM Products WHERE category IN ('Books', 'Electronics');
Attempts:
2 left
💡 Hint
Check the parentheses and commas around the list values.
✗ Incorrect
Option B is missing parentheses around the list, causing a syntax error. The IN operator requires parentheses enclosing the list.
❓ optimization
advanced2:00remaining
Optimizing WHERE with IN list for large datasets
You have a large table
Orders with millions of rows. You want to filter orders where status is in a list of 1000 possible values. Which approach is most efficient?Attempts:
2 left
💡 Hint
Consider how databases optimize joins versus large IN lists.
✗ Incorrect
Joining with a temporary table containing the 1000 values is more efficient than a large IN list or many OR conditions. Filtering in application code is inefficient.
🧠 Conceptual
advanced2:00remaining
Understanding NULL behavior with WHERE IN list
Consider a table
Students with a column grade that can be NULL. What is the result of this query?SELECT * FROM Students WHERE grade IN (NULL, 'A', 'B');
Attempts:
2 left
💡 Hint
Remember how NULL comparisons behave in SQL.
✗ Incorrect
NULL in an IN list does not match any value, including NULLs. So only rows with grade 'A' or 'B' are returned.
🔧 Debug
expert2:00remaining
Debugging unexpected results with WHERE IN list
A developer runs this query:
But the result is empty even though these product codes exist. Which option explains the most likely cause?
SELECT * FROM Inventory WHERE product_code IN ('P001', 'P002', 'P003');But the result is empty even though these product codes exist. Which option explains the most likely cause?
Attempts:
2 left
💡 Hint
Think about string matching and whitespace in SQL.
✗ Incorrect
If product_code values have trailing spaces, they won't match the exact strings in the IN list, causing no rows to be returned.