CS FundamentalsModerateProduct placement · SQL round

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?
SELECT MAX(pay) FROM Staff
WHERE pay < (SELECT MAX(pay) FROM Staff);
  1. A. 70
  2. B. 55
  3. C. NULL
  4. D. 40

Correct answer: B. 55

The inner MAX is 70 (two people earn it). The largest pay strictly below 70 is 55 — the second-highest DISTINCT pay.

More DBMS and SQL questions

Exams that ask this topic