Back-To-School Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
CTEs with data modifying statements
Summary
14. Summary

Instruction

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

  • CTE with INSERT statement:
    WITH all_customers AS (
      SELECT
        first_name,
        last_name,
        age
      FROM customer
    )
    
    INSERT INTO customers 
    SELECT *
    FROM all_customers;
    
  • CTE with 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 are familiar also with using the nested CTEs with INSERT, UPDATE, DELETE statements.

Let's go to summary exercises. Are you ready?

Exercise

Click Next exercise to continue.