CS FundamentalsHardProduct-company MCQ pattern

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). Table Dept(dname, city) rows: ('HR', 'Pune'), ('IT', 'Delhi'), ('Ops', 'Mumbai'). Which names does this query return?

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). Table Dept(dname, city) rows: ('HR', 'Pune'), ('IT', 'Delhi'), ('Ops', 'Mumbai'). Which names does this query return?
SELECT name FROM Emp
WHERE dept NOT IN (SELECT dname FROM Dept);
  1. A. No rows
  2. B. John, Lata, Dev
  3. C. John, Lata
  4. D. Dev

Correct answer: C. John, Lata

The subquery {HR, IT, Ops} has no NULL, so NOT IN works normally for Sales: John and Lata. Dev's dept is NULL, and NULL NOT IN (...) is UNKNOWN, so Dev is not returned.

More DBMS and SQL questions

Exams that ask this topic