Difficulty: Easy
Correct Answer: A way to establish an IF-THEN-ELSE in SQL.
Explanation:
Introduction / Context:
Set-based SQL lacks procedural flow like traditional languages, but it includes expressions to perform conditional evaluation inline. The CASE expression provides conditional branching (IF-THEN-ELSE) directly within SELECT, UPDATE, ORDER BY, and other clauses.
Given Data / Assumptions:
Concept / Approach:
CASE has two common forms: searched (CASE WHEN predicate THEN value ...) and simple (CASE input WHEN value THEN result ...). It evaluates conditions in order and returns the first matching result or an ELSE value; otherwise NULL if no ELSE is provided.
Step-by-Step Solution:
Verification / Alternative check:
Example: SELECT CASE WHEN total >= 100 THEN 'Gold' ELSE 'Standard' END AS tier FROM sales;
Why Other Options Are Wrong:
Loop belongs to procedural languages or PL blocks, not CASE.
Data definition uses CREATE/ALTER/DROP, unrelated to CASE.
All of the above cannot be correct because CASE is only conditional expression logic.
Common Pitfalls:
Forgetting to include an ELSE branch, which can yield NULL; or using CASE for logic that should be handled by joins or constraints.
Final Answer:
A way to establish an IF-THEN-ELSE in SQL.
Discussion & Comments