CS FundamentalsModerateGATE 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(*), COUNT(dept), COUNT(DISTINCT dept), COUNT(pay)
FROM Staff;
  1. A. 6, 5, 3, 5
  2. B. 6, 6, 3, 6
  3. C. 6, 5, 2, 5
  4. D. 5, 5, 2, 5

Correct answer: C. 6, 5, 2, 5

COUNT(*) counts rows (6); COUNT(col) skips NULLs (dept 5, pay 5); COUNT(DISTINCT dept) also ignores NULL, leaving Ops and Tech = 2.

More DBMS and SQL questions

Exams that ask this topic