I was using the following code in mysql:
delete from aluno where id=(select MAX(id) from aluno);
But the following error appears:
Error Code: 1093. You can not specify target table 'student' for update in FROM clause.
I was using the following code in mysql:
delete from aluno where id=(select MAX(id) from aluno);
But the following error appears:
Error Code: 1093. You can not specify target table 'student' for update in FROM clause.
As the rray said, it is not possible, but there are alternatives ... An alternative would be to use variables:
set @val_max = (select max(id) from aluno );
delete FROM aluno where id = @val_max;
I hope I have helped!
Any questions, leave a comment.
Can not make a DELETE
with a subquery by specifying the same table, as it says at documentation .
You can not delete from a table and select from the same table in a subquery.
You can sort by the example table id
DELETE FROM table ORDER BY the field DESC|ASC