SQL · Question 12 · Hard

SQL question 12

Table Employee:
id | name | dept | salary
1 | Asha | HR | 30000
2 | Ravi | IT | 50000
3 | Neha | IT | 60000
4 | Karan | Sales | NULL
5 | Priya | HR | 45000
6 | Vikram | IT | 50000

Table Projects has one column emp_id with rows: 1, 3, NULL

What does this query return?

SELECT COUNT(*)
FROM Employee
WHERE id NOT IN (SELECT emp_id FROM Projects);
  1. 4
  2. 3
  3. 0
  4. 6
Answer and explanation

Answer: C. 0

Explanation: x NOT IN (1, 3, NULL) means x <> 1 AND x <> 3 AND x <> NULL. The comparison with NULL is UNKNOWN, so the condition is never TRUE and no rows qualify. The count is 0.

Previous: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT… · Next: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…

Practise sql

Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.

More sql questions

More technical & programming practice

Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge