NULL Handling · Question 19 · Hard
NULL Handling question 19
Table Parcel:
id | city | agent
1 | Pune | Ravi
2 | Pune | NULL
3 | Indore | NULL
4 | Indore | Ravi
5 | Surat | Meena
What does this query return?
SELECT agent, COUNT(*), COUNT(agent)
FROM Parcel
GROUP BY agent
HAVING COUNT(agent) = 0;
- No rows
- NULL, 2, 2
- NULL, 0, 0
- NULL, 2, 0
Answer and explanation
Answer: D. NULL, 2, 0
Explanation: GROUP BY puts all NULL agents into one group. In that group COUNT(*) counts its 2 rows, while COUNT(agent) counts non-NULL values and gives 0, so it is the only group that passes the HAVING test.
Previous: Table Parcel: id | city | agent 1 | Pune | Ravi 2 | Pune | NULL 3 | Indore |… · Next: In SQL's three-valued logic, which of these expressions evaluates to FALSE…
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 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