You can't specify target table 'user' for update in FROM clause

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fhf2424045058/article/details/85096025

这个错误是Mysql的sql语句错误产生的,正如在这个博客(相关文章)所写的一样;原因是由于
在同一语句中,不能先select出同一表中的某些值,再update这个表。

 sql=
 "update user" + " set FLAG='" +lily + "' where FLAG='" + rose "' and substr(Birth_TIME,3,6) = 
                  (select * from (select min(substr(Birth_TIME,3,6)) from user" + " where FLAG='" + lily + "') a)" 
                  + "ORDER BY Birth_TIME ASC LIMIT " + user.getCount();

由于更新的时候少查询了一层select * from,所以出现这个错误,加上就好了。

猜你喜欢

转载自blog.csdn.net/fhf2424045058/article/details/85096025