WITH Clause (Common Table Expressions)

Purpose: The WITH clause allows you to define a temporary result set (Common Table Expression, or CTE) that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement, improving readability and structure.

Syntax:

WITH cte_name AS (SELECT ... )
SELECT * FROM cte_name;

Example:

WITH high_salary AS (SELECT first_name, last_name FROM employees WHERE salary > 70000)
SELECT * FROM high_salary;

Explanation: This creates a CTE named `


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *