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.
- A. (a) 1 row, (b) 1 row, (c) 0 rows
- B. (a) 0 rows, (b) 0 rows, (c) 0 rows
- C. (a) 0 rows, (b) 1 row, (c) 0 rows
- 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
- Which of the following statements about standard SQL are correct? I. A column alias defined in the SELECT list can be used in ORDER BY…
- X1(a): 1, 1, 2, 2, 3, 4 and Y1(a): 2, 4, 5. Let p = rows from SELECT a FROM X1 WHERE a NOT IN (SELECT a FROM Y1) and q = rows from SELECT…
- Tables: P(id); C(id, p) with p referencing P(id) ON DELETE CASCADE; G(id, c) with c referencing C(id) ON DELETE SET NULL. Rows: P = {1…
- Optimistic concurrency control with backward validation. Transactions (start, validation, finish times; read set; write set): T1 (0, 4, 5…
- A two-phase commit has 1 coordinator and 5 participants and uses the read-only optimisation. All 5 receive PREPARE. Three vote YES, one…
- A linear hashing file starts with 2 buckets (hash h0 = k mod 2, then h1 = k mod 4, h2 = k mod 8, ...), a bucket holds 2 keys before it…