mysql重复记录的查询删除方法
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多余的重复记录(多个字段)
SELECT * FROM C_Yyt
WHERE (Elon IN (SELECT elon FROM C_Yyt GROUP BY elon, wd HAVING COUNT(*) > 1)) AND (wd IN (SELECT wd FROM C_Yyt GROUP BY elon, wd HAVING COUNT(*) > 1))
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
6、删除重复数据
1、将重复数据中的最小的id都找出来,并插入到一个临时表中;
2、再通过表关联删除掉重复的数据;
INSERT into line_pass_init select min(id) from tt_rps_line_passzone_info_init group by plan_send_batch_dt,line_id,passid,order_flag having count(*)>1
#性能低
DELETE from tt_rps_line_passzone_info_init where id not exists (select id from line_pass_init);
#性能高
delete from tt_rps_line_passzone_info_init a where not exists(select 1 from line_pass_stor_init b where a.id=b.id);
mysql重复记录的查询删除方法的更多相关文章
- oracle中查找和删除重复记录的几种方法总结
平时工作中可能会遇到当试图对库表中的某一列或几列创建唯一索引时,系统提示 ORA-01452 :不能创建唯一索引,发现重复记录. 下面总结一下几种查找和删除重复记录的方法(以表CZ为例): 表CZ的结 ...
- PHP获取MySql新增记录ID值的方法
今天发现用mysql_insert_id()获取到的新增记录的id不正确, 虽然发现源代码的事务写的有问题,但是最根本的原因是,我插入数据的id类型是bigint型 获取MySql新增记录ID值的方法 ...
- oracel 查询删除重复记录的几种方法
建表语句CREATE TABLE Persons(PersonID int, LastName varchar(255),FirstName varchar(255),Addres ...
- SQL Server 数据库查找重复记录的几种方法
http://www.hanyu123.cn/html/c61/6790.html 一.查某一列(或多列)的重复值.(只可以查出重复记录的值,不能查出整个记录的信息) 例如:查找stuid,stuna ...
- mysql删除重复记录语句,删除除了 id 号不同,其他都相同的学生冗余信息
/** 在Mysql下执行: delete from my.stu where id not in( select min(id) id from my.stu group by code) ; 用途 ...
- 删除mysql重复记录的办法
网上有很多的办法,但是大多数都是通过临时表的办法,其实你是可以用一句简单的sql就可以做到: alter ignore table SOMETABLE add primary key(fields n ...
- 30种mysql优化sql语句查询的方法
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索 ...
- 30种mysql优化sql语句查询的方法<转>
转自百度文库 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否 ...
- mysql 开启记录慢查询记录
以下操作,基于 mysql 5.5.31 版本源码安装配置. 修改 /etc/my.cnf 中 [mysqld] 中添加如下行 # 5.3 一下的配置 log-slow-queries=/var/lo ...
随机推荐
- Sql Server 之 for xml (path,raw,auto,root)
1.for xml path('str') select ID,CreateTime from dbo.ArticleInfo for xml Path('mytitle') 结果:(注意:如果是s ...
- WebMidiLink
g200kg > WebMidiLink > 1.Introduction WebMidiLink 2012/06/26 1.Introduction « Prev 1.Introduct ...
- System.Collections.Generic的各容器类的用法
演示System.Collections.Generic的各容器类的用法. 包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSe ...
- 参数*args和**args区别
#*args(元组)和**args(字典)的区别 def tuple_test(*args): for i in args: print 'hello'+i s=('xuexi','mili') tu ...
- Hbuilder与svn快速连接并在手机上测试页面
大家好,今天讲一下Hbuilder怎样与svn连接在一起,并且在移动端上面做真是的页面测试. 1,打开Hbuilder软件,在工具中,安装插件,找到svn插件安装. 2.点击文件,导入,从svn中检测 ...
- 程序员写的东西出了bug,造成了损失谁来承担?
这是个持续多年的话题了,很多大公司,尤其是牛逼的独立分包公司(开发公司)都会有代码审核和严格QA程序,一般的公司就很难说咯,在法律上目前还没有完全支持处罚程序员bug经济损失的判例(国内如此),国外也 ...
- Chapter 1: Design the application architecture
1.1 Plan the application layers 提到了repository pattern,SoC(Separation of Concern), 进而提及MVC,Action/Act ...
- comboBox 手动输入后回车自动更新数据
C# Winform ComboBox 在输入内容时 会在下拉菜单中显示 根据输入内容查询的结果 2014-01-02 16:42匿名 | 浏览 713 次 C# ComboBox 在输入内容时 会在 ...
- Openstack入坑指南
什么是云计算 概念 云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息,可以按需求提供给计算机和其他设备.用户不需要了解”云“中的基础设施细节,不必具有相应的专业知识,也无需直接控 ...
- 040. asp.netWeb中TreeView控件绑定XML文件
xml文件格式: <?xml version="1.0" encoding="utf-8" ?> <sitemap title="进 ...