mysql - sql报错You can't specify target table 'table_name' for update in FROM clause

 

Today wrote a statement to update the database tables, the intention is based on some condition, after screening the table some data, these data delete operation, as follows

delete from t_person where id in (select id from t_person where name = "hello");

然而却报错: You can't specify target table 't_person' for update in FROM clause

The following blog post (  https://blog.csdn.net/qq_29672495/article/details/72668008  ) gives the solution: SELECT out the results through the middle of the table SELECT again, thus avoiding the error.

the correct is:

delete from t_person where id in (select temp.id from (select id from t_person where name = "hello") temp);

 

Guess you like

Origin www.cnblogs.com/zhangxuezhi/p/11593927.html