Sample questions
Question 1Easy
Which names does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT name FROM students
WHERE marks IS NULL OR city IS NULL
ORDER BY id;
- Arjun
- Arjun, Rohan
- Rohan
- No rows
Answer: B. Arjun, Rohan
Explanation
IS NULL tests for missing values correctly: Arjun has no marks and Rohan has no city.
Step-by-step solution
- IS NULL is the correct test for missing values.
- Arjun has NULL marks, and Rohan has a NULL city.
- Ordered by id, the answer is Arjun, Rohan, option B.
Why the other options are wrong
- A. Rohan also has a NULL city, so he must be included.
- C. Arjun also has NULL marks, so he must be included.
- D. IS NULL does find these rows, so the result is not empty.
Tip: OR combines two IS NULL checks; a row passes if either column is missing.
Question 2Easy
How many rows does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT name FROM students
WHERE marks = NULL;
- 0
- 1
- 5
- 6
Answer: A. 0
Explanation
Any comparison with NULL using = gives UNKNOWN, never TRUE, so no row passes. Use IS NULL instead.
Step-by-step solution
- WHERE marks = NULL compares each value with NULL.
- Any comparison made with = and NULL is UNKNOWN, which is never TRUE.
- So no row passes: 0 rows, option A.
Why the other options are wrong
- B. No row is TRUE, so the result is not one row.
- C. Five rows would need the comparison to be TRUE, and it never is.
- D. All six rows would need the comparison to be TRUE, and it never is.
Tip: Use IS NULL or IS NOT NULL to test for NULL, never = NULL.
Question 3Easy
What does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT COUNT(*), COUNT(marks), COUNT(city)
FROM students;
- 6, 5, 4
- 6, 5, 5
- 5, 5, 5
- 6, 6, 6
Answer: B. 6, 5, 5
Explanation
COUNT(*) counts rows; COUNT(column) skips NULLs. Arjun has NULL marks and Rohan has a NULL city.
Step-by-step solution
- COUNT(*) counts all 6 rows.
- COUNT(marks) skips Arjun's NULL, giving 5.
- COUNT(city) skips Rohan's NULL, giving 5, so the answer is option B, 6, 5, 5.
Why the other options are wrong
- A. COUNT(city) is 5, not 4, because only Rohan's city is NULL.
- C. COUNT(*) counts all rows, so it is 6, not 5.
- D. COUNT(marks) and COUNT(city) skip NULLs, so they are not 6.
Tip: COUNT(*) counts rows; COUNT(column) counts only non-NULL values.
Question 4Easy
Which predicate correctly finds rows where the column phone has no value?
phone = NULLphone IS NULLphone = 'NULL'phone == NULL
Answer: B. phone IS NULL
Explanation
Only IS NULL tests for NULL. = NULL is always UNKNOWN and 'NULL' is just a four-letter string.
Step-by-step solution
- To find missing values, the test must be IS NULL.
- A comparison with = NULL is UNKNOWN, so it never returns rows.
- So phone IS NULL is correct, option B.
Why the other options are wrong
- A. phone = NULL is always UNKNOWN, so it returns no rows.
- C. The text 'NULL' is a four-letter string, not a missing value.
- D. == is not SQL equality and NULL still cannot be compared with it.
Tip: Always use IS NULL or IS NOT NULL for missing values.
Question 5Medium
What does this query return?
SELECT NULL AND 0, NULL OR 1, NULL AND 1;
(SQLite shows FALSE as 0 and TRUE as 1.)
- NULL, 1, NULL
- NULL, NULL, NULL
- 0, 1, 1
- 0, 1, NULL
Answer: D. 0, 1, NULL
Explanation
Three-valued logic: UNKNOWN AND FALSE is FALSE, UNKNOWN OR TRUE is TRUE, but UNKNOWN AND TRUE stays UNKNOWN.
Step-by-step solution
- NULL AND 0: FALSE AND anything is FALSE, so the result is 0.
- NULL OR 1: TRUE OR anything is TRUE, so the result is 1.
- NULL AND 1: UNKNOWN AND TRUE stays UNKNOWN, so the result is NULL, option D.
Why the other options are wrong
- A. NULL AND 0 is FALSE, so it is 0, not NULL.
- B. NULL OR 1 is TRUE, so it is 1, not NULL; NULL AND 1 stays NULL.
- C. NULL AND 1 is UNKNOWN, so it is NULL, not 1.
Tip: FALSE AND anything is FALSE; TRUE OR anything is TRUE; otherwise NULL stays NULL.
Question 6Medium
In PostgreSQL and Oracle, where do NULL values appear by default in ORDER BY col ASC?
- In random positions
- Last
- First
- They are excluded from the result
Answer: B. Last
Explanation
PostgreSQL and Oracle treat NULL as larger than every value, so NULLs come last in ascending order (first in DESC). SQLite and MySQL do the opposite; NULLS FIRST/LAST overrides it where supported.
Step-by-step solution
- PostgreSQL and Oracle treat NULL as larger than every other value.
- In ascending order, larger values come last, so NULLs come last.
- The default position is last, option B.
Why the other options are wrong
- A. The position is fixed by the database, not random.
- C. NULLs come first in descending order in these databases, not in ascending order.
- D. NULL rows stay in the result; they are not excluded.
Tip: Check NULL ordering for each database; NULLS FIRST or NULLS LAST makes it explicit where supported.
Question 7Medium
What does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT COUNT(*) FROM students
WHERE marks > 60 OR marks <= 60;
- 0
- 4
- 5
- 6
Answer: C. 5
Explanation
The condition looks always true, but for Arjun (NULL marks) both parts are UNKNOWN, so he is excluded.
Step-by-step solution
- For Arjun,
marks is NULL. NULL > 60 is UNKNOWN and NULL <= 60 is UNKNOWN.UNKNOWN OR UNKNOWN is UNKNOWN, so he is excluded.- 5 rows remain.
Why the other options are wrong
- A. Most rows satisfy one side.
- B. More than 4 rows qualify.
- D. Arjun's row is not counted.
Tip: Test NULL with IS NULL.
Question 8Medium
What does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT AVG(marks) FROM students;
- 75.8
- 379
- 63.17
- 75
Answer: A. 75.8
Explanation
AVG ignores NULLs: (78 + 91 + 65 + 91 + 54) / 5 = 379 / 5 = 75.8, not 379 / 6.
Step-by-step solution
- AVG ignores NULL values, so Arjun's NULL is not counted.
- The sum of the five marks is 78 + 91 + 65 + 91 + 54 = 379, and the count is 5.
- 379 / 5 = 75.8, option A.
Why the other options are wrong
- B. 379 is the total, not the average.
- C. 63.17 divides by 6, which counts the NULL as zero.
- D. 75 is not the exact average; it is 75.8.
Tip: AVG is the sum divided by the count of non-NULL values; NULL is not treated as zero.
Question 9Hard
How many rows does this query return?
books
id | title | author | price | pages
1 | Atlas | Rao | 300 | 120
2 | Bloom | NULL | 250 | NULL
3 | Cipher | Iyer | NULL | 340
4 | Delta | Rao | 300 | 210
5 | Ember | Khan | 150 | 90
SELECT title FROM books
WHERE price > 200 OR pages > 100;
- 4
- 2
- 5
- 3
Answer: A. 4
Explanation
TRUE OR UNKNOWN is TRUE: Bloom passes on price 250 and Cipher on 340 pages. Only Ember (150, 90) fails both.
Step-by-step solution
- The condition is price greater than 200, OR pages greater than 100.
- Atlas, Bloom, Cipher and Delta pass; Bloom passes on price 250 and Cipher on 340 pages even though one value is NULL.
- Only Ember (150, 90) fails both, so 4 rows, option A.
Why the other options are wrong
- B. 2 leaves out Atlas and Delta, which pass on pages.
- C. 5 includes Ember, who has price 150 and 90 pages, so both tests fail.
- D. 3 misses one of the passing books.
Tip: With OR, one TRUE side is enough; a NULL on one side does not block the other side.
Question 10Hard
How many rows does this query return?
students
id | name | city | marks
1 | Kiran | Pune | 78
2 | Neha | Delhi | 91
3 | Arjun | Pune | NULL
4 | Divya | Chennai | 65
5 | Rohan | NULL | 91
6 | Sana | Delhi | 54
SELECT name FROM students
WHERE marks NOT IN (54, 65, NULL);
- 4
- 3
- 2
- 0
Answer: D. 0
Explanation
x NOT IN (54, 65, NULL) means x <> 54 AND x <> 65 AND x <> NULL. The last part is always UNKNOWN, so no row can be TRUE.
Step-by-step solution
- NOT IN is a chain of not-equal checks joined by AND, and the list includes NULL.
- A NULL check can never be TRUE, so the whole condition is never TRUE for any row.
- So no row passes: 0 rows, option D.
Why the other options are wrong
- A. 4 would need the NULL check to pass, which it never does.
- B. 3 would need the NULL check to pass, which it never does.
- C. 2 would need the NULL in the list to be ignored, which SQL does not do.
Tip: A NULL inside NOT IN makes the whole condition never TRUE; remove NULLs from the list.
Practise all 26 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →