NULL Handling · Question 10 · Medium

NULL Handling question 10

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

The NOT IN list below contains a NULL. What does the query return?

SELECT COUNT(*)
FROM Staff
WHERE id NOT IN (1, 3, NULL);
  1. 3
  2. 2
  3. 0
  4. 5
Answer and explanation

Answer: C. 0

Explanation: id NOT IN (1, 3, NULL) means id <> 1 AND id <> 3 AND id <> NULL. The last part is never TRUE, so the whole condition is FALSE for ids 1 and 3 and UNKNOWN for the rest. No row qualifies.

Previous: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |… · Next: Table Parcel: id | city | agent 1 | Pune | Ravi 2 | Pune | NULL 3 | Indore |…

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