From the course: Advanced SQL: Logical Query Processing, Part 2

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Recursions

Recursions - SQL Tutorial

From the course: Advanced SQL: Logical Query Processing, Part 2

Start my 1-month free trial

Recursions

- [Instructor] So far we've used many WITH clauses. They helped us break down complex tasks, shorten queries, but there's much more to them than that. WITH clauses pack a powerful and unique ability to process recursions without resorting to any type of imperative solutions. To create a recursive WITH clause, we must specify our intent using the WITH recursive keyword, the recursive query definition consists of two parts. The first is a standalone, ordinary select query called the anchor. The anchor defines the initial set, the starting point for the recursion. The anchor query is followed by either a union all or a union distinct set operator, which in turn is followed by the recursive query itself. The recursion is indicated by referencing the WITH clause name within the query. This may seem counterintuitive at first, as typically, we cannot reference an object within its own definition. As for the processing, first, the…

Contents