一 mysql去重操作
1查看是否有重复数据(根据唯一字段name_s 查询表hc)
SELECT name_s,COUNT(*) FROM hc GROUP BY name_s HAVING COUNT(*) > 1
2查询数据表中重复字段中的一个
select * from hc where name_s in (select name_s from hc group by name_s having count(name_s) > 1)
and id in (select min(id) from hc group by name_s having count(name_s)>1)
3mysql插入重复数据到另一个临时表hc2
insert into hc2 (select * from hc where name_s in (select name_s from hc group by name_s having count(name_s) > 1) and id not in (select min(id) from hc group by name_s having count(name_s)>1))
4删除表一和表二中相同的数据
delete a.* from hc a, hc2 b where a.id = b.id ;
5如果想保持表1中id连续则创建表3将表一中除了id之外其他字段全部添加到表3
insert into hc3(name_s,mobile_s,phone_s,url_s,people_s) (select name_s,mobile_s,phone_s,url_s ,people_s from hc)
二
1创建一个临时表,其中包含要删除的重复记录的 `Url` 值。
CREATE TABLE tmp_table AS SELECT Url FROM your_table_name GROUP BY Url HAVING COUNT(*) > 1;
2删除重复数据
DELETE FROM your_table_name WHERE Url IN (SELECT Url FROM tmp_table);
3删除零时表
DROP TABLE IF EXISTS tmp_table;