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; 4
- No rows
- 1; 2; 3; 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
- A table Voter has 10 rows, and the city column is NULL in exactly 3 of them…
- Table Student: roll | name 1 | Irfan 2 | Jaya 3 | Kunal 4 | Lata Table Hostel…
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- Table Parcel: id | city | agent 1 | Pune | Ravi 2 | Pune | NULL 3 | Indore |…
- In SQL's three-valued logic, which of these expressions evaluates to FALSE…
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