L
L
Lancelot2021-08-09 12:51:47
MySQL
Lancelot, 2021-08-09 12:51:47

MySQL 8 CTE and Update?

Hello. Is it possible to update something in MySQL 8.0.22 in CTE?

WITH
  tmpCustomer AS (
    SELECT c.customer_id AS id, c.email
    FROM oc_order r
    INNER JOIN oc_customer c ON c.customer_id = r.customer_id
    WHERE r.order_status_id = 6 AND c.customer_group_id < 3
    GROUP BY c.customer_id
    HAVING COUNT(*) > 4
  ),
  tmpCustomerU AS (
    UPDATE oc_customer SET customer_group_id = 3 WHERE customer_id IN (SELECT id FROM tmpCustomer)
  )
  SELECT email FROM tmpCustomer

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question