0
0
C Sharp (C#)programming~20 mins

Where clause filtering in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Where Clause Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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
A["Alice", "Bob", "Charlie", "Diana"]
B["Alice", "Diana"]
C["Bob", "Charlie"]
D[]
Attempts:
2 left
💡 Hint
Think about which employees have Age greater than 30.
📝 Syntax
intermediate
2: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;
ASELECT * FROM Products WHERE Price <= 100;
BSELECT * FROM Products WHERE Price <= 100 OR Quantity > 10;
CSELECT * FROM Products WHERE Price <= 100 AND Quantity > 10;
DSELECT * FROM Products WHERE Price <= 100 AND;
Attempts:
2 left
💡 Hint
Look for incomplete logical expressions after AND.
optimization
advanced
2: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 OrderDate column. Which WHERE clause is most efficient?

Assume OrderDate is a datetime type.
AWHERE OrderDate &gt;= '2023-01-01' AND OrderDate &lt; '2024-01-01'
BWHERE OrderDate &gt;= '2023-01-01' OR OrderDate &lt; '2024-01-01'
CWHERE YEAR(OrderDate) = 2023
DWHERE OrderDate &gt; '2022-12-31' AND YEAR(OrderDate) = 2023
Attempts:
2 left
💡 Hint
Using functions on indexed columns can prevent index usage.
🧠 Conceptual
advanced
2: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
ARows with GraduationDate not equal to '2023-06-01', excluding NULLs
BRows with GraduationDate not equal to '2023-06-01', including NULLs
COnly rows where GraduationDate is NULL
DNo rows, because NULL comparison returns false
Attempts:
2 left
💡 Hint
Remember how SQL treats NULL in comparisons.
🔧 Debug
expert
2:00remaining
Debugging unexpected WHERE clause behavior
You run this query:

SELECT * FROM Employees WHERE Department = 'Sales' OR 'Marketing';

It returns all rows, not just Sales or Marketing. Why?
AThe Department column does not contain 'Marketing' values.
BThe condition 'Marketing' is treated as a constant TRUE, so the WHERE clause always passes.
CThe query is missing parentheses around the OR conditions.
DThe OR operator is invalid here and causes a syntax error.
Attempts:
2 left
💡 Hint
Check how SQL evaluates non-boolean expressions in WHERE.