> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/common-table-expressions.md).

# Common Table Expressions (CTE)

{% columns %}
{% column %}
{% content-ref url="/pages/S1LP85cv69g5DPELrbJ2" %}
[Recursive Common Table Expressions Overview](/docs/server/reference/sql-statements/data-manipulation/selecting-data/common-table-expressions/recursive-common-table-expressions-overview.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
Process hierarchical data using recursive CTEs. These expressions reference themselves to repeatedly execute a subquery, perfect for traversing tree structures or generating sequences.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/cQKt58i9nOnTQ0deaMkx" %}
[Non-Recursive Common Table Expressions Overview](/docs/server/reference/sql-statements/data-manipulation/selecting-data/common-table-expressions/non-recursive-common-table-expressions-overview.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
Define simple temporary result sets. Non-recursive CTEs act like query-local views, improving readability by allowing you to define and reuse subqueries within a single statement.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/3HkX4nh7k5oboVO4JY5p" %}
[WITH](/docs/server/reference/sql-statements/data-manipulation/selecting-data/common-table-expressions/with.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
Complete WITH clause reference: WITH \[RECURSIVE] AS (SELECT...) syntax, recursive CTE support, CYCLE...RESTRICT cycle detection, and max\_recursive\_iterations.
{% endcolumn %}
{% endcolumns %}
