SQLIntermediate#queries#cte

What is a CTE (Common Table Expression)?

A named temporary result set declared with WITH and referenced by the following statement. It improves readability, can be referenced multiple times and supports recursion.

Example
WITH top_customers AS (
  SELECT customer_id, SUM(total) AS spend
  FROM orders GROUP BY customer_id
)
SELECT * FROM top_customers WHERE spend > 10000;

Related Questions

1
SQLAdvanced#cte

How do you write a recursive CTE?

Open
2
SQLIntermediate#views

What is a view? What is a materialized view?

Open
3
SQLIntermediate#transactions

Explain the ACID properties.

Open