SQL Functions & CASE · Question 10 · Medium

SQL Functions & CASE question 10

Table Student:
roll | name | marks
1 | Aarav | 82
2 | Diya | 67
3 | Kabir | 45
4 | Meher | 91
5 | Rohan | 30
6 | Sneha | NULL

What does this query return for the student whose marks are NULL?

SELECT name,
       CASE WHEN marks >= 40 THEN 'Pass' ELSE 'Fail' END
FROM Student
WHERE roll = 6;
  1. Sneha, NULL
  2. Sneha, Fail
  3. Sneha, Pass
  4. No rows
Answer and explanation

Answer: B. Sneha, Fail

Explanation: NULL >= 40 is UNKNOWN, which is not true, so the WHEN branch is skipped and the ELSE value is used. CASE returns NULL only when no branch matches and there is no ELSE.

Previous: Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45… · Next: Table Payment: id | mode | amount | status 1 | UPI | 500 | SUCCESS 2 | CARD |…

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