Bird
0
0

Which of the following is the correct syntax to use CASE inside an ORDER BY clause?

easy📝 Syntax Q12 of 15
SQL - CASE Expressions
Which of the following is the correct syntax to use CASE inside an ORDER BY clause?
AORDER BY CASE WHEN condition THEN value ELSE value END
BORDER BY IF condition THEN value ELSE value END
CORDER BY SWITCH condition THEN value ELSE value END
DORDER BY SELECT CASE condition THEN value ELSE value END
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct CASE syntax in ORDER BY

    The correct syntax uses CASE WHEN ... THEN ... ELSE ... END without extra keywords.
  2. Step 2: Identify incorrect keywords

    Options A, B, and C use invalid keywords like SELECT, IF, or SWITCH which are not valid in ORDER BY CASE.
  3. Final Answer:

    ORDER BY CASE WHEN condition THEN value ELSE value END -> Option A
  4. Quick Check:

    CASE syntax = WHEN THEN ELSE END [OK]
Quick Trick: Use CASE WHEN ... THEN ... ELSE ... END in ORDER BY [OK]
Common Mistakes:
  • Using IF instead of CASE
  • Adding SELECT inside ORDER BY
  • Using SWITCH keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes