Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive ctes
Summary
34. Summary

Instruction

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

  • A recursive CTE is a CTE that refers to itself.
  • The general syntax is:

    WITH CteName AS (
      SELECT
        ... -- anchor member
      UNION ALL
      SELECT
        ...
      FROM CteName ... -- recursive member
      WHERE .... -- termination check
    )
    
    SELECT (DISTINCT)
      ...
    FROM CteName ... -- 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.