如何实现mysql数据库删除重复记录?

    作者:课课家教育更新于: 2016-03-25 15:15:44

      一个数据表要是存在很多的重复记录,是很占内存的,在MySQL数据表中有很多的命令是用于删除重复记录的,今天给大家介绍下删除重复记录的方法。

    如何实现mysql数据库删除重复记录?_数据库_mysql删除重复记录_课课家

      如果出现重复记录,就需要进行删除操作,下面为您介绍了几种MySQL删除重复记录的方法,希望对您能够有所帮助。

      MySQL删除重复记录是我们经常用到的操作,下面为您介绍了5种MySQL删除重复记录的方法,如果您感兴趣的话,不妨一看。

      1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

      select*frompeople

      wherepeopleIdin(selectpeopleIdfrompeoplegroupbypeopleIdhavingcount(peopleId)>1)

      2、查找表中多余的重复记录(多个字段)

      select*fromvitaea

      where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhavingcount(*)>1)

      3、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

      deletefrompeople

      wherepeopleIdin(selectpeopleIdfrompeoplegroupbypeopleIdhavingcount(peopleId)>1)

      androwidnotin(selectmin(rowid)frompeoplegroupbypeopleIdhavingcount(peopleId)>1)

      4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录

      deletefromvitaea

      where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhavingcount(*)>1)

      androwidnotin(selectmin(rowid)fromvitaegroupbypeopleId,seqhavingcount(*)>1)

      5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录

      select*fromvitaea

      where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhavingcount(*)>1)

      androwidnotin(selectmin(rowid)fromvitaegroupbypeopleId,seqhavingcount(*)>1)

课课家教育

未登录

1