0

On MySQL, this does not run:

delete from robottinosino where date = (select max(date) from robottinosino);

Error message:

ERROR 1093 (HY000): You can't specify target table 'robottinosino' for update in FROM clause

Question:

  • Why? (emphasis on the "why" so the Q is not inaccurately marked as "duplicate")
  • How to fix it?
2

1 Answer 1

5

MySQL doesn't allow you to delete from a table that you're also selecting from. It's a race condition in many cases - you could be deleting records from the table before the select part of the query has had a chance to retrieve them.

In your case, the query should be allowed, because there isn't any danger of this race, but MySQL isn't smart enough to figure that out.

There're a workarounds here: MySQL Error 1093 - Can't specify target table for update in FROM clause

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.