NULL Handling · Question 11 · Medium

NULL Handling question 11

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

How many rows does this query return?

SELECT DISTINCT agent
FROM Parcel;
  1. 2 rows: Ravi and Meena
  2. 3 rows: Ravi, Meena and one NULL
  3. 4 rows: Ravi, Meena and two NULLs
  4. 5 rows, because NULLs stop DISTINCT from removing duplicates
Answer and explanation

Answer: B. 3 rows: Ravi, Meena and one NULL

Explanation: For DISTINCT, all NULLs are treated as duplicates of each other, even though NULL = NULL is not true in a WHERE clause. The two NULL agents collapse into a single NULL row, next to Ravi and Meena.

Previous: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |… · 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

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