WITH clause
Description
A
WITHclause is an optional clause that precedes the SELECT INTO in a query. TheWITHclause defines one or more common_table_expressions. Each common table expression (CTE) defines a temporary table, which is similar to a view definition. You can reference these temporary tables in theFROMclause. (Redshift SQL Language Reference WITH Clause)
The WITH clause is fully supported in Snowflake.
Grammar Syntax
[ WITH [RECURSIVE] common_table_expression [, common_table_expression , ...] ]
--Where common_table_expression can be either non-recursive or recursive.
--Following is the non-recursive form:
CTE_table_name [ ( column_name [, ...] ) ] AS ( query )
--Following is the recursive form of common_table_expression:
CTE_table_name (column_name [, ...] ) AS ( recursive_query )Sample Source Patterns
Non-Recursive form
Input Code:
2
102
2024-02-02
600.00
4
104
2024-02-04
750.00
5
105
2024-02-05
900.00
Output Code:
2
102
2024-02-02
600.00
4
104
2024-02-04
750.00
5
105
2024-02-05
900.00
Recursive form
Input Code:
101
John
100
103
Kwaku
101
102
Jorge
101
110
Liu
101
106
Mateo
102
201
Sofía
102
105
Richard
103
110
Nikki
103
104
Paulo
103
120
Saanvi
104
200
Shirley
104
205
Zhang
104
Output Code:
101
John
100
103
Kwaku
101
102
Jorge
101
110
Liu
101
106
Mateo
102
201
Sofía
102
105
Richard
103
110
Nikki
103
104
Paulo
103
120
Saanvi
104
200
Shirley
104
205
Zhang
104
Known Issues
There are no known issues.
Related EWIs.
There are no related EWIs.
Last updated
