Find duplicate records in MySQL

后端 未结 23 2825
别跟我提以往
别跟我提以往 2020-11-21 23:12

I want to pull out duplicate records in a MySQL Database. This can be done with:

SELECT address, count(id) as cnt FROM list
GROUP BY address HAVING cnt >         


        
23条回答
  •  旧巷少年郎
    2020-11-21 23:50

        Find duplicate Records:
    
        Suppose we have table : Student 
        student_id int
        student_name varchar
        Records:
        +------------+---------------------+
        | student_id | student_name        |
        +------------+---------------------+
        |        101 | usman               |
        |        101 | usman               |
        |        101 | usman               |
        |        102 | usmanyaqoob         |
        |        103 | muhammadusmanyaqoob |
        |        103 | muhammadusmanyaqoob |
        +------------+---------------------+
    
        Now we want to see duplicate records
        Use this query:
    
    
       select student_name,student_id ,count(*) c from student group by student_id,student_name having c>1;
    
    +--------------------+------------+---+
    | student_name        | student_id | c |
    +---------------------+------------+---+
    | usman               |        101 | 3 |
    | muhammadusmanyaqoob |        103 | 2 |
    +---------------------+------------+---+
    

提交回复
热议问题