SQL: Common table expression reference
19 March 2023 (Updated 22 October 2023)
On this page
In a nutshell
A common table expression (CTE) is a temporary named result set that you can reference within a SELECT
, INSERT
, UPDATE
, or DELETE
statement. CTEs can make your queries more readable and performant.
Example
You create a CTE by starting with the WITH
statement and then defining a subquery. You can then reference the CTE in a SELECT
, INSERT
, UPDATE
, or DELETE
statement.
Other notes
- Common table expressions were introduced to MySQL 8.0 so they will only work from 8.0 onwards.
Sources
Tagged:
MySQL
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment