These behave in the same manner as nested subqueries but with a different syntax.
WITH ReadyCars AS (
SELECT *
FROM Cars
WHERE Status = 'READY'
)
SELECT ID, Model, TotalCost
FROM ReadyCars
ORDER BY TotalCost;
ID | Model | TotalCost |
---|---|---|
1 | Ford F-150 | 200 |
2 | Ford F-150 | 230 |
Equivalent subquery syntax
SELECT ID, Model, TotalCost
FROM (
SELECT *
FROM Cars
WHERE Status = 'READY'
) AS ReadyCars
ORDER BY TotalCost