You can’t specify target table 'pessoa' for update in FROM clause

Asked

Viewed 295 times

-2

I am testing the operation of a subquery (subconsulta) and executing the command below:

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

the following error occurs:

You can’t specify target table 'pessoa' for update in FROM clause

1 answer

1

As described in the documentation of Mysql:

You cannot delete from a table and select from the same table in a subquery.

That is, you cannot delete records from the same table you used in a sub-query. And it doesn’t even make sense to do that, because it’s to exclude on condition nome = 'isac', then just do:

DELETE FROM pessoa WHERE nome = 'isac';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.