NULL Handling · Question 16 · Hard
NULL Handling question 16
Table Student:
roll | name
1 | Irfan
2 | Jaya
3 | Kunal
4 | Lata
Table Hostel:
room | roll
101 | 1
102 | NULL
103 | 3
Table Hostel lists room allotments; room 102 is not yet allotted. Which names does this query return?
SELECT s.name
FROM Student s
WHERE NOT EXISTS (SELECT 1 FROM Hostel h
WHERE h.roll = s.roll)
ORDER BY s.name;
- Jaya; Lata
- No rows
- Irfan; Kunal
- Jaya; Kunal; Lata
Answer and explanation
Answer: A. Jaya; Lata
Explanation: NOT EXISTS only asks whether the subquery finds a matching row. Rolls 1 and 3 have a match; for rolls 2 and 4 no Hostel row makes h.roll = s.roll true (the NULL row never matches), so Jaya and Lata are returned. The same question written with NOT IN would return no rows because of the NULL.
Previous: A table Voter has 10 rows, and the city column is NULL in exactly 3 of them… · 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
- Table Feedback: id | student | rating 1 | Tanvi | 4 2 | Umesh | 0 3 | Varun |…
- Table Customer: id | name | mobile | email 1 | Farhan | 9810012345 | NULL 2 |…
- A table Voter has 10 rows, and the city column is NULL in exactly 3 of them…
- 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 |…
- 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