NULL Handling · Question 3 · Easy

NULL Handling question 3

Table Staff:
id | name | dept | bonus
1 | Anita | HR | 5000
2 | Bhavesh | IT | NULL
3 | Charu | IT | 8000
4 | Deepak | Sales | NULL
5 | Esha | HR | 3000

What does this COALESCE query return?

SELECT name, COALESCE(bonus, 0)
FROM Staff
WHERE dept = 'IT'
ORDER BY name;
  1. Bhavesh, NULL; Charu, 8000
  2. Charu, 8000
  3. Bhavesh, 0; Charu, 0
  4. Bhavesh, 0; Charu, 8000
Answer and explanation

Answer: D. Bhavesh, 0; Charu, 8000

Explanation: COALESCE returns its first argument that is not NULL. Bhavesh has a NULL bonus, so 0 is shown for him; Charu's 8000 is not NULL and is returned unchanged.

Previous: In SQL's three-valued logic, what does the comparison NULL = NULL evaluate to? · Next: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…

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