SQL Functions & CASE · Question 16 · Hard

SQL Functions & CASE question 16

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

This query uses the simple form of CASE (CASE marks WHEN ...). What does it return?

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

Answer: D. Sneha, Present

Explanation: CASE marks WHEN NULL compares with an equals test, marks = NULL, which is UNKNOWN even when marks is NULL. The branch never matches, so ELSE gives Present. To catch NULL, write CASE WHEN marks IS NULL THEN ...

Previous: Which statement about the SQL CASE expression is correct? · 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