AI engineering glossary · SQL databases
What is CTE (common table expression)?
Common table expression (also called CTE, WITH clause): A named temporary result defined with WITH at the start of a query and used like a table in the rest of it. It splits long queries into readable steps and can be referenced several times.
Common table expression: an example
WITH big AS (SELECT * FROM orders WHERE amount > 1000) SELECT city, COUNT(*) FROM big GROUP BY city;
Related terms
More SQL databases terms
Where you learn it
Common table expression is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.