【mysql 】sql删除重复记录 You can't specify target table '表名' for update in FROM clause

用下面的语句就报语法出错:

delete from tab_record where recordid not in
(select  min(c.recordid) as recordid from  tab_record  c group by (c.dev_Id+c.StartTime+c.EndTime+c.CardNum));

 报错如下:You can't specify target table '表名' for update in FROM clause

找到替代方案,改用下面的,OK:

delete from tab_record where recordid not in
(select min(c.recordid) as recordid from (select * from tab_record ) c group by (c.dev_Id+c.StartTime+c.EndTime+c.CardNum));

或者下面的也OK:

delete from tab_record where recordid not in
(select * from (
  select min(recordid) as recordid from tab_record group by (dev_Id+StartTime+EndTime+CardNum)) v);

posted @ 2013-06-20 15:18  祺祺怪怪的  阅读(6210)  评论(1编辑  收藏  举报