0
0
SQLquery~5 mins

CASE in WHERE clause in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the CASE statement do inside a WHERE clause?
It allows you to apply conditional logic to decide which rows to include based on different conditions.
Click to reveal answer
beginner
How do you write a simple CASE expression inside a WHERE clause?
Use WHERE CASE WHEN condition THEN value ELSE other_value END = something to filter rows based on conditions.
Click to reveal answer
intermediate
Can CASE in WHERE clause return different columns or just values?
CASE returns values, not columns. It helps decide which value to compare in the WHERE filter.
Click to reveal answer
intermediate
Why use CASE in WHERE instead of multiple OR conditions?
CASE can make complex conditions clearer and easier to manage by grouping logic in one expression.
Click to reveal answer
beginner
Example: How to filter rows where status is 'active' if type is 1, else 'pending'?
Use WHERE (CASE WHEN type = 1 THEN status ELSE 'pending' END) = 'active' to apply this logic.
Click to reveal answer
What does the CASE statement inside a WHERE clause return?
AA value to compare
BA column name
CA table
DA SQL command
Which keyword is used to start a CASE expression?
AWHEN
BELSE
CTHEN
DCASE
Can you use ELSE in a CASE inside WHERE clause?
ANo, ELSE is not allowed
BYes, to provide a default value
COnly if there is one WHEN
DOnly in SELECT, not WHERE
Which is a valid use of CASE in WHERE clause?
AWHERE CASE WHEN age > 18 THEN 'adult' ELSE 'minor' END = 'adult'
BWHERE CASE age > 18 THEN 'adult' ELSE 'minor' END
CWHERE CASE age > 18 'adult' ELSE 'minor' END
DWHERE CASE age > 18 THEN 'adult' ELSE 'minor'
Why might you use CASE in a WHERE clause?
ATo join tables
BTo create new tables
CTo apply different filters based on conditions
DTo sort results
Explain how CASE can be used inside a WHERE clause to filter data conditionally.
Think about how CASE returns a value that the WHERE clause compares.
You got /5 concepts.
    Write a simple example of a SQL query using CASE in the WHERE clause to filter rows based on different conditions.
    Try filtering rows where a column value changes the filter condition.
    You got /5 concepts.