您好,欢迎访问一九零五行业门户网

SQL如何删除重复数据

在sql中,可以使用select语句删除重复数据,语法为:“select * from 字段 where 字段id in (select 字段id from 字段 group by 字段 having count(字段id) > 1)”。
本教程操作环境:windows7系统、mysql8.0版本、dell g3电脑。
用sql语句,删除掉重复项只保留一条
在几千条记录里,存在着些相同的记录,如何能用sql语句,删除掉重复的呢
查找表中多余的重复记录,重复记录是根据单个字段(peopleid)来判断 
select * from people where peopleid in (select peopleid from people group by peopleid having count(peopleid) > 1)
扩展:
删除表中多余的重复记录,重复记录是根据单个字段(peopleid)来判断,只留有rowid最小的记录
delete from peoplewhere peoplename in (select peoplename from people group by peoplename having count(peoplename) > 1)and peopleid not in (select min(peopleid) from people group by peoplename having count(peoplename)>1)
查找表中多余的重复记录(多个字段)
select * from vitae awhere (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq having count(*) > 1)
删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae awhere (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)
查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae awhere (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)
消除一个字段的左边的第一位:
update tablename set [title]=right([title],(len([title])-1)) where title like '村%'
消除一个字段的右边的第一位:
update tablename set [title]=left([title],(len([title])-1)) where title like '%村'
假删除表中多余的重复记录(多个字段),不包含rowid最小的记录
update vitae set ispass=-1where peopleid in (select peopleid from vitae group by peopleid
相关推荐:《mysql教程》
以上就是sql如何删除重复数据的详细内容。
其它类似信息

推荐信息