CS FundamentalsVery hardGATE 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 e LEFT JOIN Emp m ON e.mgr = m.eid WHERE m.dept = 'D1' OR m.dept IS NULL;

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

Correct answer: D. 6

Five employees (Bin, Cy, Dev, Eli, Gus) have a manager in D1, and Aru (no manager) survives because the left join pads m with NULLs: 6. 7 wrongly keeps Fay by reading her own NULL dept (her manager Cy is in D2); 3 counts distinct D1 managers and 1 only the padded row.

More DBMS and SQL questions

Exams that ask this topic