删除数据库中重复的记录,只保留一条 DELETE FROM tb_gps_records WHERE id NOT IN (SELECT bid FROM (SELECT min(id) as bid FROM tb_gps_records GROUP BY busNo,longitude,latitude)as b); //cityId=287 DELETE FROM tb_gps_records WHERE cityId=287 and id NOT IN (SELECT bid FROM…
正好想写一条删除重复语句并保留一条数据的SQL,网上查了一部分资料写的很详细,但还是在这里写下自己的理解,以遍后续学习 .如下: 表字段和数据: SQL语句: [sql] view plain copy DELETE FROM `user` WHERE id NOT IN(SELECT * FROM(SELECT id FROM `user` GROUP BY username)AS b) 理解: 先从里面的SQL开始看 1.SELECT id FROM `user` GROUP BY user…
MYSQL里有五百万数据,但大多是重复的,真实的就180万,于是想怎样把这些重复的数据搞出来,在网上找了一圈,好多是用NOT IN这样的代码,这样效率很低,自己琢磨组合了一下,找到一个高效的处理方式,用这个方式,五百万数据,十来分钟就全部去除重复了,请各位参考. 第一步:从500万数据表data_content_152里提取出不重复的字段SFZHM对应的ID字段到TMP3表 create table tmp3 as select min(id) as col1 from data_content…