@H_403_1@MysqL实现查重只留一个的方法:首先通过“select * from”查找表中多余的重复记录;然后通过“delete from”删除重复数据,并只保留一个数据即可。@H_403_1@@H_403_1@推荐:《mysql视频教程》@H_403_1@MysqL 删除重复数据只保留一条记录@H_403_1@删除重复数据保留name中ID最小的记录
delete from order_info where ID not in (select ID from (select min(ID) as ID from order_info group by order_number) as b);@H_403_1@
delete from table where ID not in (select min(ID) from table group by name having count(name)>1) and ID in (select ID group by name having count(name)>1)@H_403_1@(注意:HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似。WHERE 搜索条件在进行分组 *** 作之前应用;而 HAVING 搜索条件在进行分组 *** 作之后应用。HAVING 语法与 WHERE 语法类似,但 HAVING 可以包含聚合函数。HAVING 子句可以引用选择列表中显示的任意项。)@H_403_1@ @H_403_1@扩展:@H_403_1@ @H_403_1@sql:删除重复数据,只保留一条用SQL语句,删除掉重复项只保留一条在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢@H_403_1@ @H_403_1@ 1、查找表中多余的重复记录,重复记录是根据单个字段(peopleID)来判断
select * from people where peopleID in (select peopleID from people group by peopleID having count(peopleID) > 1)@H_403_1@2、删除表中多余的重复记录,重复记录是根据单个字段(peopleID)来判断,只留有rowID最小的记录
delete from people where 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)@H_403_1@3、查找表中多余的重复记录(多个字段)
select * from vitae a where (a.peopleID,a.seq) in (select peopleID,seq from vitae group by peopleID,seq having count(*) > 1)@H_403_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)@H_403_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)@H_403_1@6.消除一个字段的左边的第一位:
update tablename set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'@H_403_1@7.消除一个字段的右边的第一位:
update tablename set [Title]=left([Title],(len([Title])-1)) where Title like '%村'@H_403_1@8.假删除表中多余的重复记录(多个字段),不包含rowID最小的记录
update vitae set ispass=-1 where peopleID in (select peopleID from vitae group by peopleID,seq having count(*) > 1) and seq in (select 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)总结
以上是内存溢出为你收集整理的mysql如何实现查重只留一个全部内容,希望文章能够帮你解决mysql如何实现查重只留一个所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)