Recursive Common Table Expressions Overview

You are viewing an old version of this article. View the current version here.

Common Table Expressions (CTEs) are a standard SQL feature, and are essentially temporary named result sets.

There are two kinds of CTEs:

SQL is generally poor at recursive structures.

trees_and_graphs

Oracle first attempted something similar in the 1980's with the CONNECT BY syntax. They appeared in the SQL standard in 1999, and the first implementations began appearing in 2007.

Syntax

Attachment 'recursive_cte_syntax' not found

cte_syntax

Computation

Given the following structure: Attachment 'recursive_cte_computation' not found

First execute the anchor part of the query: Attachment 'recursive_cte_computation_1' not found

Next, execute the recursive part of the query: Attachment 'recursive_cte_computation_2' not found

Attachment 'recursive_cte_computation_2b' not found

Attachment 'recursive_cte_computation_3' not found

Attachment 'recursive_cte_computation_3b' not found

Attachment 'recursive_cte_computation_4' not found

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.