CS FundamentalsHardGATE CS · SQL

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 COUNT(*) FROM Staff a, Staff b
WHERE a.pay = b.pay AND a.id < b.id;
  1. A. 8
  2. B. 7
  3. C. 2
  4. D. 1

Correct answer: D. 1

Only Chitra and Farid share a pay (70), giving one pair with a.id < b.id. Dev's NULL never equals anything, not even itself.

More DBMS and SQL questions

Exams that ask this topic