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 e.name
FROM Staff e JOIN Staff b ON e.boss = b.id
WHERE e.pay > b.pay
ORDER BY e.name;
  1. A. Chitra, Farid
  2. B. Bala, Chitra, Farid
  3. C. Bala, Chitra
  4. D. Bala, Chitra, Dev, Farid

Correct answer: B. Bala, Chitra, Farid

Compare each employee with their boss: Bala 55 > Anu 40, Chitra 70 > 40, Farid 70 > Bala 55. Dev's pay is NULL (comparison unknown) and Esha 35 < Chitra 70.

More DBMS and SQL questions

Exams that ask this topic