CS FundamentalsModerateGATE CS

Table T(x) holds the values 1, NULL, 3, NULL, 3. What does SELECT COUNT(*), COUNT(x), COUNT(DISTINCT x) FROM T return?

  1. A. 5, 3, 2
  2. B. 5, 5, 3
  3. C. 3, 3, 2
  4. D. 5, 3, 3

Correct answer: A. 5, 3, 2

COUNT(*) counts all 5 rows, COUNT(x) skips NULLs (3), and COUNT(DISTINCT x) counts the distinct non-NULL values 1 and 3 (2).

More DBMS and SQL questions

Exams that ask this topic