NULL Handling · Question 17 · Hard
NULL Handling question 17
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
A developer expects this condition to be true for every row. What does the query return?
SELECT COUNT(*)
FROM Staff
WHERE bonus > 4000 OR NOT (bonus > 4000);
- 5
- 3
- 0
- 2
Answer and explanation
Answer: B. 3
Explanation: For the two rows with a NULL bonus, bonus > 4000 is UNKNOWN and NOT (UNKNOWN) is also UNKNOWN, so the OR is UNKNOWN and the row is dropped. Only the 3 rows with a known bonus are counted; "p OR NOT p" is not always true in SQL.
Previous: Table Student: roll | name 1 | Irfan 2 | Jaya 3 | Kunal 4 | Lata Table Hostel… · 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
- 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 Student: roll | name 1 | Irfan 2 | Jaya 3 | Kunal 4 | Lata Table Hostel…
- 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