当前位置:数据库 > MySQL >>

mysql删除重复记录的sql语句与查询重复记录(1/4)


方法1
delete yourtable
where [id] not in (
select max([id]) from yourtable
group by (name + value))
方法2
delete a
from 表 a left join(
select (id) from 表 group by name,value
)b on a.id=b.id
where b.id is null
查询及删除重复记录的sql语句
查询及删除重复记录的sql语句
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 vitae a
where (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq having count(*) > 1) 

1 2 3 4
补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,