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
  • 31,909
  • 5
  • 12
  • 21
Muamar Humaidi
  • 319
  • 2
  • 9

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
  • 888
  • 10
  • 51