Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The very basics
Infinite looping
Processing graphs with recursive CTE
Summary
32. Revision

Instruction

Excellent! Ok, it's time to wrap things up.

  • 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 our recursion.
  • The recursive member must query the same CTE.
  • The termination check is used to stop the recursion at some point.
  • The invocation is used to actually show any results.

Okay, are you ready for a short quiz?

Exercise

Click Next exercise to continue.