WITH keyword
Supports Common Table Expressions (CTEs), e.i., naming one or several
sub-queries to be used with a SELECT
,
INSERT
, or
UPDATE
query.
Using a CTE makes it easy to simplify large or complex statements which involve sub-queries, particularly when such sub-queries are used several times.
#
SyntaxWhere:
alias
is the name given to the sub-query for ease of reusingsubQuery
is a SQL query (e.gSELECT * FROM table
)
#
ExamplesSingle alias
Using recursively
Flag whether individual trips are longer or shorter than average
Update with a sub-query
Insert with a sub-query