NULL Handling · Question 18 · Hard

NULL Handling question 18

Table Parcel:
id | city | agent
1 | Pune | Ravi
2 | Pune | NULL
3 | Indore | NULL
4 | Indore | Ravi
5 | Surat | Meena

Which ids does this query return?

SELECT id
FROM Parcel
WHERE agent IN ('Ravi', NULL)
ORDER BY id;
  1. 1; 4
  2. No rows
  3. 1; 2; 3; 4
  4. 2; 3
Answer and explanation

Answer: A. 1; 4

Explanation: agent IN ('Ravi', NULL) means agent = 'Ravi' OR agent = NULL. For ids 1 and 4 the first part is TRUE, and TRUE OR UNKNOWN is TRUE. The NULL in the list never matches the NULL agents, and unlike NOT IN it does not wipe out the result.

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