Mysql You can't specify target table for update in FROM clause
1093 - You can't specify target table 'table_name' for update in FROM clause;
不能先select出同一表中的某些值,再update这个表(在同一语句中)
原语句:
delete from i_user where b_code in (
select b_code from i_user
group by b_code
HAVING count(u_code) > 1) limit 1;
修改后:即增加一个中间表作为查询结果,再删除
delete from i_user where b_code in (
select b_code from (
select b_code from i_user
group by b_code
HAVING count(u_code) > 1) t) limit 1;
该问题只会出现在:mysql
oracle 以及 sqlServer 不会出现