MySQL in your can ' t specify target table for update in FROM clause error means that you cannot select some of the values in the same table first, and then update the table (in the same statement). For example, the following SQL:
The code is as follows:
Delete from the TBL where ID in
(
Select Max (ID) from TBL a where EXISTS
(
Select 1 from the TBL B where A.tac=b.tac GROUP by TAC has count (1) >1
)
Group BY TAC
)
Rewrite it to the following line:
Copy the code code as follows:
Delete from the TBL where ID in
(
Select a.ID from
(
Select MAX (ID) ID from tbl a where EXISTS
(
Select 1 from the TBL B where A.tac=b.tac GROUP by TAC has count (1) >1
)
Group BY TAC
) A
)
In other words, the result of select is passed through the intermediate table select again, thus avoiding the error. Note that this issue only occurs in Mysql,mssql and Oracle does not occur.
MySQL error:you can ' t specify target table for update on FROM clause