Reusing Results of Subqueries

Function

To improve query performance, caching the results of a subquery and reusing them in different parts of the query can be done to avoid redundant calculations of the same subquery during the execution of a SELECT statement.

Syntax

1
2
3
4
5
6
7
8
WITH cte_name AS (
    SELECT ...
    FROM table_name
	WHERE ...
)
SELECT ...
FROM cte_name
WHERE ...

Keywords

Table 1 Keywords

Parameter

Description

cte_name

Custom subquery name

table_name

Name of the table where subquery commands are executed

Example