ReferenceApplies to: Unified engine deployments
A common table expression names an intermediate query within one statement. A subquery places a query inside another query. Neither automatically persists its result as a table.
Common table expressions
Use WITH to make a query easier to read. A CTE is scoped to its statement. Later CTEs can refer to earlier ones. Recursive CTEs and materialization modifiers are unavailable.
Derived tables
A subquery in FROM is a derived table. Give it an alias. It is useful for filtering a window result because QUALIFY is unavailable.
Scalar subqueries
A scalar subquery supplies a single value. It must return at most one row. Zero rows produce NULL; multiple rows produce an error. Aggregate subqueries are a convenient way to guarantee one row.
EXISTS and IN
EXISTS tests whether its subquery returns any rows. IN compares against returned values. NOT IN can become NULL when its input contains NULL, so do not substitute it for NOT EXISTS without considering null semantics. Correlated and null-aware forms can be restricted by the selected backend; an ordinary key join is often easier to inspect.
Last modified on November 4, 2026