NULL Handling · Question 14 · Medium

NULL Handling question 14

Table Customer:
id | name | mobile | email
1 | Farhan | 9810012345 | NULL
2 | Gauri | NULL | [email protected]
3 | Harsh | NULL | NULL

What does this query return?

SELECT name, COALESCE(mobile, email, 'none')
FROM Customer
WHERE id >= 2
ORDER BY id;
  1. Gauri, NULL; Harsh, NULL
  2. Gauri, [email protected]; Harsh, none
  3. Gauri, [email protected]; Harsh, NULL
  4. Gauri, none; Harsh, none
Answer and explanation

Answer: B. Gauri, [email protected]; Harsh, none

Explanation: COALESCE checks its arguments from left to right and returns the first one that is not NULL. Gauri has no mobile, so her email is used; Harsh has neither, so the last argument 'none' is returned.

Previous: Table Feedback: id | student | rating 1 | Tanvi | 4 2 | Umesh | 0 3 | Varun |… · Next: A table Voter has 10 rows, and the city column is NULL in exactly 3 of them…

Practise null handling

Try a fresh set of null handling questions with an explanation after every answer, free and without signing up: NULL Handling practice. Or sit a full placement mock test.

More null handling questions

More sql practice

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

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