Product upgrade issue

1

In query the goal is to update the product unit, with a subquery that retrieves the current drive from the database and subtracts by checking by code.

UPDATE loja.produto SET UNIDADE = (SELECT (SELECT UNIDADE FROM loja.produto WHERE CODIGO = '212212121') - 1 ) WHERE CODIGO = '212212121';

I have the following error:

  

0 100 13:54:14 UPDATE PRODUCT SET UNIT = (SELECT (SELECT UNIT   FROM store.product WHERE CODE = '212212121') - 1) WHERE CODE =   '212212121' Error Code: 1093. You can not specify target table 'PRODUCT'   for update in FROM clause 0.000 sec

    
asked by anonymous 05.09.2015 / 18:56

1 answer

3

I do not know if I understand what you want but it seems to me that you only need this:

UPDATE loja.produto SET UNIDADE = UNIDADE - 1 WHERE CODIGO = '212212121';
    
05.09.2015 / 18:59