You can not specify target table 'person' for update in FROM clause

-2

I'm testing the operation of a subquery (subquery) and running the command below:

DELETE FROM pessoa
WHERE id IN(SELECT id FROM pessoa 
             WHERE id=2
             );

The following error occurs:

  

You can not specify target table 'person' for update in FROM clause

    
asked by anonymous 24.08.2018 / 16:04

1 answer

1

As described in the MySQL documentation:

  

That is, you can not delete records from the same table that you used in a sub-query. And it does not make sense to do this, because if it's to exclude with the condition nome = 'isac' , then it would suffice to do:

DELETE FROM pessoa WHERE nome = 'isac';
    
24.08.2018 / 16:44