In mysql, You can't specify target table for update in FROM clause. specifyclause
In mysql, You can't specify target table for update in FROM clause errors mean that some values in the same table cannot be selected first, update the table (in the same statement ). For example, the following SQL statement:
Copy codeThe Code is as follows:
Delete from tbl where id in
(
Select max (id) from tbl a where EXISTS
(
Select 1 from tbl B where a. tac = B. tac group by tac HAVING count (1)> 1
)
Group by tac
)
Rewrite it to the following:
Copy codeThe Code is as follows:
Delete from tbl where id in
(
Select a. id from
(
Select max (id) id from tbl a where EXISTS
(
Select 1 from tbl B where a. tac = B. tac group by tac HAVING count (1)> 1
)
Group by tac
)
)
That is to say, the result of the select statement is then passed through the select statement in the middle table, thus avoiding errors. Note that this problem only occurs in mysql, and does not occur in mssql and oracle.