Incorrectly, you cannot select some values from the same table first, and then update the table (in the same statement). For example, the following SQL:
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:
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
)
Again as: UPDATE BK_YGSBK as bk SET report_visit = (SELECT COUNT (*) from BK_YGSBK where Zyid = ' 1 ') where BK. Zyid = ' 1 '
Should be changed to: UPDATE BK_YGSBK as bk SET report_visit = (SELECT * FROM [select COUNT (*) from BK_YGSBK WHERE Zyid = ' 1 ') as R) wher E BK. Zyid = ' 1 '
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: [ERR] 1093-you can ' t specify target table ' BK ' for update on FROM clause