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. Which name does this query return? SELECT name FROM Emp WHERE sal = (SELECT MAX(sal) FROM Emp WHERE sal < (SELECT MAX(sal) FROM Emp WHERE dept = 'D1'));

  1. A. Cy
  2. B. Fay
  3. C. Aru
  4. D. Bin and Dev

Correct answer: B. Fay

The D1 maximum is 90 (Aru). The largest salary in the whole table below 90 is Fay's 75; the middle subquery is not restricted to D1, so Cy's 70 is not the answer.

More DBMS and SQL questions

Exams that ask this topic