Bird
0
0

Given the table Tasks with column priority having values 'High', 'Medium', 'Low', what will the query below return?

medium📝 query result Q13 of 15
SQL - CASE Expressions
Given the table Tasks with column priority having values 'High', 'Medium', 'Low', what will the query below return?

SELECT priority FROM Tasks ORDER BY CASE priority WHEN 'High' THEN 1 WHEN 'Medium' THEN 2 ELSE 3 END;
ARows sorted with 'High' first, then 'Medium', then 'Low'.
BRows sorted alphabetically by priority.
CRows sorted with 'Low' first, then 'Medium', then 'High'.
DSyntax error due to CASE in ORDER BY.
Step-by-Step Solution
Solution:
  1. Step 1: Understand CASE assigns sorting values

    CASE assigns 1 to 'High', 2 to 'Medium', and 3 to others (like 'Low').
  2. Step 2: ORDER BY sorts ascending by these values

    Rows with priority 'High' come first, then 'Medium', then 'Low'.
  3. Final Answer:

    Rows sorted with 'High' first, then 'Medium', then 'Low'. -> Option A
  4. Quick Check:

    CASE assigns order numbers = sorted by priority [OK]
Quick Trick: CASE assigns numbers to priorities to sort custom order [OK]
Common Mistakes:
  • Assuming alphabetical sort
  • Thinking CASE causes syntax error
  • Confusing order direction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes