What does the following recursive CTE produce? WITH RECURSIVE nums AS ( SELECT 1 AS n UNION ALL SELECT n + 1 FROM nums WHERE n < 5 ) SELECT n FROM nums

SQL Fundamentals Hard

SQL Fundamentals — Hard

What does the following recursive CTE produce? WITH RECURSIVE nums AS ( SELECT 1 AS n UNION ALL SELECT n + 1 FROM nums WHERE n < 5 ) SELECT n FROM nums

Key points

  • The CTE starts with 1 and adds 1 to each subsequent row
  • The recursion stops when the condition n < 5 is no longer met
  • The final result includes rows 1, 2, 3, 4, and 5

Ready to go further?

Related questions