It's Autumn! Prices fall like leaves! - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The very basics
Infinite looping
Processing graphs with recursive CTEs
Summary
32. Revision

Instruction

Amazing work! It's time to wrap things up. In this part, we learned that:

  • A recursive CTE is a CTE that refers to itself.
  • The general syntax is:
    WITH RECURSIVE cte_name AS (
      SELECT 
        ... -- anchor member
      UNION (ALL)
      SELECT 
      ... 
      FROM cte_name ... -- recursive member
      WHERE .... -- termination check
    )
    
    SELECT 
      ... 
    FROM cte_name ... -- invocation
  • The anchor member is the starting point for recursion.
  • The recursive member must query the same CTE.
  • The termination check stops the recursion at some point.
  • The invocation is used to show any results.

Okay, are you ready for a short quiz?

Exercise

Click Next exercise to continue.