Home > Database > Mysql Tutorial > body text

MySQL中删除重复数据的简单方法_MySQL

WBOY
Release: 2016-06-01 13:00:13
Original
768 people have browsed it

MYSQL里有五百万数据,但大多是重复的,真实的就180万,于是想怎样把这些重复的数据搞出来,在网上找了一圈,好多是用NOT IN这样的代码,这样效率很低,自己琢磨组合了一下,找到一个高效的处理方式,用这个方式,五百万数据,十来分钟就全部去除重复了,请各位参考。

第一步:从500万数据表data_content_152里提取出不重复的字段SFZHM对应的ID字段到TMP3表

create table tmp3 as select min(id) as col1 from data_content_152 group by SFZHM;

Copy after login

第二步:创建新表RES

CREATE TABLE `res` (
`id` int(11),
`sfz` char(20)
) ENGINE=MyISAM;
Copy after login

第三步:把TMP3表ID对应到data_content_152里需要提取的数据添加到RES表的SFZ字段

INSERT INTO res (sfz) SELECT sfzhm FROM data_content_152,tmp3 where data_content_152.id=tmp3.col1
Copy after login

至此,就在MYSQL里实现了,给数据表data_content_152完全删除重复数据,把去重复后的数据导入到RES表。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!