WITH keyword
Name one or several sub-queries to be used within the main query.
This clause makes it easy to simplify large or complex statements which involve sub-queries, particularly when such sub-queries are used several times.
Syntax#
Where:
subQueryNameis the alias for the sub-querysubQueryis a SQL query (e.gSELECT * FROM table)mainQueryis the main SQL query which involves thesubQueryusing its alias.
Examples#
Single alias
Using recursively
Flag whether individual trips are longer or shorter than average