NULL Handling · Question 1 · Easy

NULL Handling question 1

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

Which names does this query return?

SELECT name
FROM Staff
WHERE bonus IS NULL
ORDER BY name;
  1. Anita; Charu; Esha
  2. No rows, because nothing can be compared with NULL
  3. Bhavesh; Deepak
  4. Anita; Bhavesh; Charu; Deepak; Esha
Answer and explanation

Answer: C. Bhavesh; Deepak

Explanation: IS NULL is the test made for missing values, and it is true for exactly the rows whose bonus is NULL: Bhavesh and Deepak.

Next: In SQL's three-valued logic, what does the comparison NULL = NULL evaluate to?

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