CS FundamentalsHardGATE CS (PYQ pattern)

Table T(x) has 4 rows. How many rows does each of these return? (a) SELECT COUNT(*) FROM T HAVING COUNT(*) > 5; (b) SELECT COUNT(*) FROM T WHERE 1 = 0; (c) SELECT x FROM T GROUP BY x HAVING COUNT(*) > 5, if x has 4 distinct values.

  1. A. (a) 1 row, (b) 1 row, (c) 0 rows
  2. B. (a) 0 rows, (b) 0 rows, (c) 0 rows
  3. C. (a) 0 rows, (b) 1 row, (c) 0 rows
  4. D. (a) 1 row, (b) 0 rows, (c) 4 rows

Correct answer: C. (a) 0 rows, (b) 1 row, (c) 0 rows

An aggregate query without GROUP BY forms one group, so (b) returns one row (COUNT = 0). HAVING then filters that single group: (a) the group fails COUNT(*) > 5, giving no rows. In (c) every group has 1 row, so none qualifies.

More DBMS and SQL questions

Exams that ask this topic