DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

Recursion — Example 98

Quick explanation + ready code for: Recursion.

SQL Recursion Back to examples
Back to language
Syntax: Recursion in SQL. ID: #98

Code

WITH RECURSIVE t(n) AS (
  SELECT 1
  UNION ALL
  SELECT n+1 FROM t WHERE n < 4
)
SELECT * FROM t;

Notes

You can copy this snippet and adapt it. For advanced, add real-world inputs, edge cases, and tests.