mysql 简单去重语句

简单去重语句

方式一:

# mn_y去重
ALTER TABLE mn_y ADD UNIQUE (name, href)

select * from mn_y limit 1

select COUNT(id) from mn_y

select count(id) as '重复次数',name from mn_y group by name having count(*)>1 order by name desc

create table mn_y_copy select * from mn_y
where id in (
select max(id) from mn_y group by name
)
drop table mn_y
ALTER TABLE mn_y_copy RENAME TO mn_y

方式二:

DELETE from mn_y_copy where id not in (
select aa.id from (
select max(id) id from mn_y_copy it group by title
) aa
)

发表回复

关闭菜单