mysql error 1093

Error Code: 1093. You can’t specify target table ‘t_user’ for update in FROM clause 0.015 SEC
data cannot be query in the same table as update data in the same table.
note that this problem occurs only in mysql; MSSQL and oracle do not.
Keyword search: mysql Error 1093
Example:


delete from t_user where id in (select id from t_user where id > 26);
Error Code: 1093. You can’t specify target table ‘t_user’ for update in FROM clause 0.000 SEC

Solution: select the result of the select through the intermediate table again, so as to avoid the error
change the SQL statement to:

delete from t_user where id in (select * from (select id from t_user where id > 26) tmp);

Then optimize it:

delete t from t_user t join (select id from t_user where id > 22) tmp on tmp.id = t.id;

query data in the same table as the same table update or delete delete, the SQL statement is as follows:
select * from (clause temp)

Read More: