$ ./guess_the_languageSQL & Databases
SQL & Databases · hard · #6

What does the query return?

WITH RECURSIVE n(x) AS (
  SELECT 1
  UNION ALL
  SELECT x * 2 FROM n WHERE x < 20
)
SELECT MAX(x) FROM n;
  1. 16
  2. 32
  3. 64
  4. 20
The CTE yields 1, 2, 4, 8, 16, 32: the row 16 still passes x < 20, so 32 is produced before recursion stops.
Play SQL & Databases ▸