skip to today's puzzle

WITH gives a result a temporary name

Sometimes a query needs a result that doesn't exist as a table yet. WITH lets you build that result first and give it a temporary name — called a common table expression, or CTE — then use that name in the query that follows, exactly as if it were a real table. The name only lives for that one query.

A tiny example

In plain English: Give the order list a temporary name, then show me everything in it.

WITH big_orders AS (
  SELECT id, total
  FROM orders
  WHERE total >= 20
)
SELECT *
FROM big_orders;

Query result

idtotal
10224.5
10731
11022.75

big_orders isn't a real table — it's the named result of the SELECT inside WITH, used just for this one query.

Related SQL lessons

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle