Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Using CTEs with data-modifying statements
Summary
14. Summary

Instruction

Perfect! It's time to sum up your knowledge of using CTEs with data-modifying statements. In this part, you have learned how to use a:

  • CTE with an INSERT statement:
    WITH all_customers AS (
      SELECT
        first_name,
        last_name,
        age
      FROM customer
    )
    
    INSERT INTO customers 
    SELECT *
    FROM all_customers;
    
  • CTE with a UPDATE statement:
    WITH products AS (
      SELECT 
        id
      FROM product
      WHERE id IN (1,4,6,7)
    )
    
    UPDATE product
    SET price = price - 0.05 
    WHERE id IN (SELECT id FROM products); 
    
  • CTE with DELETE statement:
    WITH customer_remove AS (
      SELECT
        id 
      FROM customer 
      WHERE first_name = 'Ema'
      AND last_name = 'Green'
    )
    
    DELETE FROM customer
    WHERE id = (SELECT id FROM customer_remove);
    

You also know how to use nested CTEs with INSERT, UPDATE, and DELETE statements.

Let's do a short review before we move on to the final quiz for this course. Are you ready?

Exercise

Click Next exercise to continue.