delete from demo_user where id in(
//获取重复记录的 id
select id from demo_user
where id > any (select id from demo_user where age in (select age from demo_user group by age having count(age) > 1))
and id <= some (select id from demo_user where age in (select age from demo_user group by age having count(age) > 1))
);
报了 error: You can't specify target table 'demo_user' for update in FROM clause
1
20150517 2016-11-19 00:00:04 +08:00 3
先要删的记录先 insert into xxxx (select xxx from xxxx)
然后再 delete from xxx where id in (select xxx from xxxx) |
2
Layne 2016-11-19 00:50:02 +08:00
楼上说的这是流着泪积累的经验,楼主你值得拥有。。
|
3
ihuotui 2016-11-19 01:05:43 +08:00 via Android
就是用一个 id 唯一索引的表保存一次,然后改表名,即有备份又得到结果
|
4
dalang 2016-11-19 07:44:22 +08:00 via iPhone
我一般都是先把要操作的 table duplicate 一份
|
7
rockpk008 2016-11-19 09:46:43 +08:00 via iPhone
一楼绝壁有过故事
|