CTE

Abbreviation · Development

Definitions

  1. Common Table Expression — a named temporary result set defined within a SQL statement using the WITH clause. Makes complex queries readable by breaking them into logical steps. Recursive CTEs can traverse hierarchical data (org charts, threaded comments, bill of materials). Available in PostgreSQL, MySQL 8+, SQLite, and all major databases.

    In plain English: A named subquery in SQL that makes complex queries more readable by breaking them into named steps.

    Example: "WITH active_users AS (SELECT * FROM users WHERE status = 'active') SELECT * FROM active_users JOIN orders... — CTEs make the query self-documenting."

Related Terms