WITH CTE | SQL Tutorial and Query Example

Text copied!

WITH CTE


  • WITH cte_name (column1, column2, column3, ...)
    AS (
        -- Query definition for the CTE
        SELECT column1, column2, column3, ...
        FROM table_name
        WHERE condition
    )
    -- Main query using the CTE
    SELECT column1, column2, column3, ...
    FROM cte_name
    WHERE condition;