SQL Functions & CASE · Question 15 · Medium

Which statement about the SQL CASE expression is correct?

  1. It can be written only in the SELECT list
  2. It produces a value, so it can be used in SELECT, WHERE, ORDER BY and inside aggregate functions
  3. Every CASE must have an ELSE part, or the query does not run
  4. All WHEN conditions are evaluated and the last true one decides the result
Answer and explanation

Answer: B. It produces a value, so it can be used in SELECT, WHERE, ORDER BY and inside aggregate functions

Explanation: CASE is an expression, so it is allowed wherever a value is allowed. ELSE is optional (it defaults to NULL), and the first true WHEN decides the result, not the last.

Previous: Table Salary: emp | basic | bonus Nikhil | 30000 | 5000 Ojas | 40000 | NULL… · Next: Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…

Practise sql functions & case

Try a fresh set of sql functions & case questions with an explanation after every answer, free and without signing up: SQL Functions & CASE practice. Or sit a full placement mock test.

More sql functions & case questions

More sql practice

UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge