CS FundamentalsModerateGATE 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. Which rows does this query return? SELECT mgr, COUNT(*) FROM Emp GROUP BY mgr HAVING COUNT(*) >= 2;

  1. A. (1, 2) and (2, 2)
  2. B. (1, 2), (2, 2) and (NULL, 1)
  3. C. (1, 2) only
  4. D. (1, 3) and (2, 3)

Correct answer: A. (1, 2) and (2, 2)

Aru (1) manages Bin and Cy, Bin (2) manages Dev and Eli; Cy and Dev manage one each and the NULL group holds only Aru, so those groups fail HAVING COUNT(*) >= 2.

More DBMS and SQL questions

Exams that ask this topic