mysql删除重复数据行,只保留一条 ? ? delimiter $$create table `devices_all` ( `device_all_id` int(11) not null auto_increment, `device_id` varchar(512) default null, `device_token` varchar(512) default null, `client_agent` varchar(512) defau
mysql删除重复数据行,只保留一条
?
?
delimiter $$
create table `devices_all` (
`device_all_id` int(11) not null auto_increment,
`device_id` varchar(512) default null,
`device_token` varchar(512) default null,
`client_agent` varchar(512) default null,
`create_time` datetime default null,
primary key (`device_all_id`)
) engine=myisam auto_increment=49 default charset=latin1$$
?
表名devices_all,判重列device_id。?
?
delete from devices_all
where device_id in (select device_id from (select device_id from devices_all a group by a.device_id having count(a.device_id) > 1) as a)
and device_all_id not in (select device_all_id from (select min( device_all_id) device_all_id from devices_all group by device_id having count( device_id)>1) as b)
.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}
申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!