mysql删除重复记录提示#1093 – You can’t specify target table ‘X’ for update in FROM clause

使用以下语句删除重复记录时候出现错误提示,据说mssql和oracle不会出现此问题。

delete from table where (countid) in (

 select min(countid) as countid from table where year=2017 group by objname,objid,year having count(1) > 1

)

提示#1093 – You can’t specify target table ‘X’ for update in FROM clause

大概意思是你不能select出来后同时又更新

解决方案 要不就create table tmp 创建个临时表,要不就再套个select

 

delete from table where (countid) in (
 select a.countid from
 (
 select min(countid) as countid from table where year=2017 group by objname,objid,year having count(1) > 1
 )a
)
此条目发表在服务器分类目录,贴了标签。将固定链接加入收藏夹。

发表评论