CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2, 'D1', 60), (5, 'Eli', 2, 'D2', 40), (6, 'Fay', 3, NULL, 75), (7, 'Gus', 4, 'D1', 30). mgr refers to eid. What does this query return? SELECT COUNT(*) FROM Emp WHERE eid NOT IN (SELECT mgr FROM Emp);

  1. A. 3
  2. B. 4
  3. C. 0
  4. D. 7

Correct answer: C. 0

The subquery returns {NULL, 1, 1, 2, 2, 3, 4}. For any eid not in the list, eid NOT IN (...) compares against the NULL and becomes UNKNOWN, never TRUE, so no row qualifies. NOT EXISTS would correctly return the 3 non-managers.

More DBMS and SQL questions

Exams that ask this topic