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.
Syntax#
Where:
aliasis the name given to the sub-query for ease of reusingsubQueryis a SQL query (e.gSELECT * FROM table)
Examples#
Single alias
Using recursively
Flag whether individual trips are longer or shorter than average
Update with a sub-query
Insert with a sub-query