Blog · Guide

SQL CTEs Explained: WITH Clauses You Can Read

A CTE (WITH …) names a temporary result so multi-step queries stay readable — great for “paid orders first, then …”.

customers first_name last_name city result first_name · city
SELECT chooses which columns appear in the result.

Name a step, then use it

WITH paid AS (
  SELECT * FROM orders WHERE status = 'paid'
)
SELECT * FROM paid;

Same power as a subquery, clearer when you chain logic. Think of it as a named scratch table for one query.

Try it yourself

The fastest way to lock this in is a short drill on the same Northstar Market tables.

Practice a CTE

Related guides