NULL Handling questions and answers
Three-valued logic, IS NULL, COALESCE and NULL in aggregates. Practise null handling questions from the sql section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.
Sample null handling questions with worked answers
Question 1
In SQL's three-valued logic, what does the comparison NULL = NULL evaluate to?
- UNKNOWN
- TRUE
- FALSE
- A syntax error
Answer: A. UNKNOWN
Explanation: NULL stands for a missing or unknown value, so comparing two unknowns cannot be called true or false. Every ordinary comparison that involves NULL gives UNKNOWN, and WHERE keeps only rows whose condition is TRUE.
Question 2
A table Voter has 10 rows, and the city column is NULL in exactly 3 of them. The query SELECT COUNT(*) FROM Voter WHERE city = 'Pune' returns 4. What does SELECT COUNT(*) FROM Voter WHERE city <> 'Pune' return?
- 6
- 7
- 3
- 0
Answer: C. 3
Explanation: The 3 NULL rows satisfy neither city = 'Pune' nor city <> 'Pune', because both comparisons are UNKNOWN for them. That leaves 10 - 4 - 3 = 3 rows with a known city other than Pune.
Question 3
In SQL's three-valued logic, which of these expressions evaluates to FALSE (not to UNKNOWN)?
- NULL AND TRUE
- NULL OR FALSE
- NULL AND FALSE
- NOT (NULL = NULL)
Answer: C. NULL AND FALSE
Explanation: AND is FALSE as soon as one side is FALSE, whatever the unknown side might be, so NULL AND FALSE is FALSE. NULL AND TRUE and NULL OR FALSE depend on the unknown value and stay UNKNOWN, and NOT of UNKNOWN is UNKNOWN.
All 20 null handling questions with answers
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- In SQL's three-valued logic, what does the comparison NULL = NULL evaluate to?
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- What does the function NULLIF(a, b) return?
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- 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 Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |…
- 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 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 |…
- 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…
NULL Handling: common questions
What are null handling questions?
Three-valued logic, IS NULL, COALESCE and NULL in aggregates. They appear in the sql section of many placement tests.
Where can I practise null handling questions with answers for free?
Right here on LogicWiz Exams. Every null handling question has a worked explanation after you answer. Practice is free and needs no sign-up.
How should I practise null handling?
Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.
Start practising
On this page you can start a fresh set of null handling questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: SQL practice.
More sql topics
- SELECT, WHERE & ORDER BY: Filtering, DISTINCT, IN, BETWEEN, LIKE, sorting and LIMIT.
- SQL Joins: Inner, left, right, full, cross and self joins, and row counts.
- Aggregates & GROUP BY: COUNT, SUM, AVG, grouping and HAVING versus WHERE.
- Subqueries & CTEs: Scalar and correlated subqueries, IN, EXISTS and WITH.
- Window Functions: ROW_NUMBER, RANK, DENSE_RANK, PARTITION BY, LAG and running totals.
- SQL Functions & CASE: CASE WHEN, conditional aggregation, string and numeric functions.
- UNION, INTERSECT & EXCEPT: Combining results, duplicates and column rules.
- Tables, Keys & Constraints: CREATE, ALTER, primary and foreign keys, UNIQUE and CHECK.
- DML & Transactions: INSERT, UPDATE, DELETE, COMMIT, ROLLBACK and ACID.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Technical & Programming: CS fundamentals, output prediction and pseudo-code: the technical MCQ round for IT roles.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep