Challenge - 5 Problems
Where Clause Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Filtering rows with WHERE clause
Given a table Employees with columns
Id, Name, and Age, what will be the output of this query?SELECT Name FROM Employees WHERE Age > 30;C Sharp (C#)
Employees table data: Id | Name | Age 1 | Alice | 28 2 | Bob | 35 3 | Charlie | 40 4 | Diana | 25
Attempts:
2 left
💡 Hint
Think about which employees have Age greater than 30.
✗ Incorrect
The WHERE clause filters rows where Age is greater than 30. Only Bob (35) and Charlie (40) satisfy this.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in WHERE clause
Which option contains a syntax error in the WHERE clause of this SQL query?
SELECT * FROM Products WHERE Price <= 100 AND;Attempts:
2 left
💡 Hint
Look for incomplete logical expressions after AND.
✗ Incorrect
Option D ends the WHERE clause with AND but no condition after it, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing WHERE clause for performance
You want to retrieve all orders placed in 2023 from a large Orders table with an index on the
Assume
OrderDate column. Which WHERE clause is most efficient?Assume
OrderDate is a datetime type.Attempts:
2 left
💡 Hint
Using functions on indexed columns can prevent index usage.
✗ Incorrect
Option A uses a range condition that allows the database to use the index efficiently. Option A uses a function YEAR() on the column, which disables index use.
🧠 Conceptual
advanced2:00remaining
Understanding WHERE clause with NULL values
Given a table Students with a column
GraduationDate that can be NULL, what does this query return?SELECT * FROM Students WHERE GraduationDate != '2023-06-01';C Sharp (C#)
Students table data: Id | Name | GraduationDate 1 | John | 2023-06-01 2 | Mary | NULL 3 | Steve | 2023-05-30
Attempts:
2 left
💡 Hint
Remember how SQL treats NULL in comparisons.
✗ Incorrect
In SQL, NULL compared with any value using != returns UNKNOWN, which is treated as false in WHERE. So rows with NULL GraduationDate are excluded.
🔧 Debug
expert2:00remaining
Debugging unexpected WHERE clause behavior
You run this query:
It returns all rows, not just Sales or Marketing. Why?
SELECT * FROM Employees WHERE Department = 'Sales' OR 'Marketing';It returns all rows, not just Sales or Marketing. Why?
Attempts:
2 left
💡 Hint
Check how SQL evaluates non-boolean expressions in WHERE.
✗ Incorrect
The string 'Marketing' alone is a truthy constant, so the WHERE clause is effectively always true, returning all rows.