CS FundamentalsHardProduct-company SDE · GATE CS

What does this query return (SQL:1999 recursive CTE; runs as written in SQLite and PostgreSQL)? WITH RECURSIVE t(n) AS (SELECT 1 UNION ALL SELECT n * 2 FROM t WHERE n < 50) SELECT COUNT(*), MAX(n) FROM t;

  1. A. 6 and 32
  2. B. 7 and 32
  3. C. 7 and 64
  4. D. 6 and 64

Correct answer: C. 7 and 64

The WHERE tests the previous row, so 32 < 50 still produces 64; then 64 fails and recursion stops. Rows: 1, 2, 4, 8, 16, 32, 64, so 7 rows with maximum 64.

More DBMS and SQL questions

Exams that ask this topic