0

Query :

UPDATE `master_customer`  
SET `customer_group_id` = 19 
WHERE `customer_code` IN( SELECT * 
                          FROM `master_customer` a,
                               `master_customer_group` b
                          WHERE a.`customer_group_id` = b.`id`
                            AND b.`id` = 8);

Result:

Query: UPDATE `master_customer` SET `customer_group_id` = 19 WHERE `customer_code` IN( SELECT a.`customer_code` FROM `master_customer` ...

Error Code: 1093 You can't specify target table 'master_customer' for update in FROM clause

Akina
  • 39,301
  • 5
  • 14
  • 25
Muamar Humaidi
  • 329
  • 4
  • 12

1 Answers1

0

It is a MySQL feature. You can work it around by wrapping subquery to yet another subquery :)

UPDATE `master_customer`  SET `customer_group_id` = 19 WHERE `customer_code` IN( 
SELECT x.customer_code FROM (
SELECT a.customer_code FROM
    `master_customer` a,
    `master_customer_group` b
    WHERE
    a.`customer_group_id` = b.`id`
    AND b.`id` = 8) AS x
) 

https://stackoverflow.com/a/33607415/272885

artoodetoo
  • 918
  • 10
  • 55