Introduction to Recursion
Learn to implement recursion in MySQL.
We'll cover the following
Recursion is a phenomenon where something is defined in terms of itself. In computer science, recursion refers to a function that calls itself as part of its definition. In the sense of divide and conquer, recursion poses the opportunity to solve a complex problem in smaller, simple steps. So far, our understanding of SQL without recursion implies that a query terminates since SQL cannot loop forever. At the same time, we know that any SQL query can be evaluated efficiently in
A practical example of recursion
Given this promise, we will illustrate the benefit of recursive computation based on the Fibonacci numbers. The Fibonacci sequence is a series of numbers that starts with 0 and 1, and each subsequent number is the sum of the two preceding it.
Mathematically, the Fibonacci numbers are defined as
From a programming language perspective, like TypeScript, we know that the Fibonacci numbers can be computed iteratively and recursively. Iterative computation uses a loop to calculate each number in turn, while recursive computation involves calling a function that calls itself until the desired number is reached.
Get hands-on with 1400+ tech skills courses.