MySQL Error Message
You can’t specify target table ‘%s’ for update in FROM
clause
Reason for the Error
This error occurs for attempts to select from and modify the same
table within a single statement. If the select attempt occurs
within a derived table, you can avoid this error by setting the
derived_merge flag of the
optimizer_switch system variable
to force the subquery to be materialized into a temporary table,
which effectively causes it to be a different table from the one
modified. See Optimizing Derived Tables, View References, and Common Table Expressions with Merging or Materialization.