dtv8189 2017-03-22 23:44
浏览 94
已采纳

MYSQL重复条目

i am trying to find duplicate entries within my mysql table. I would like to compare the different fields with each other. Here is the structure of my table:

ID    FirstName    LastName    Street    ZIP      City        IpAddress
 1      Jack        Smith       2nd     12345    Sample1     12.21.24.212
 2      Paul        Miller      3rd     45685    Sample2     78.54.85.654
 3      Jenny       Smith       3rd     77273    Sample3     84.91.67.311
 4      Frank       Jackson     1st     27819    Sample1     78.54.85.654
 5      Jack        Smith       3rd     72891    Sample2     94.79.99.465

Now i would like to compare the street and ip column individually and then i would like to find the combination of the first- and lastname. There are actually a few more columns in my table that i would like to search for but i think my example above should give you an idea about what i am planning.

I need the id numbers of the entries that could potencially duplicates.

In the example above the output should be the id numbers 1 and 5 when i compare the combination of the first- and lastname.

The output should be the id numbers 2,3 and 5 if i compare the street names.

And the output for the ip addresses should be id numbers 2 and 4.

Does anyone have some ideas about how i should do this? What is the best way to compare those different tables? I don't mind if i have to do several queries.

  • 写回答

1条回答 默认 最新

  • dourui9570 2017-03-22 23:49
    关注

    Use GROUP_CONCAT() to get all the IDs within a group, and GROUP BY to specify the columns that you're looking for duplidates of. And you can use COUNT(*) so you only return the ones that have duplicates.

    For streets:

    SELECT street, GROUP_CONCAT(id)
    FROM yourTable
    GROUP BY street
    HAVING COUNT(*) > 1
    

    For names:

    SELECT firstname, lastname, GROUP_CONCAT(id)
    FROM yourTable
    GROUP BY firstname, lastname
    HAVING COUNT(*) > 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起