Translate

Tuesday, June 16, 2015

How To Find Duplicate Records in MYSQL



In this tutorial, I will explain how to find duplicate records in MYSQL.
I think the best way to explain is using an example:

This is our table called actors:




As you can see, we have  the name JULIO several times, which is fine because it won't affect anything, but what would happen if someone told you how many JULIO'S  we have in our actors tables?

To do that, we need the next SQL statement:
   

  select count(a.first_name)as 'Duplicate Records', 
        a.actor_id,a. first_name
  from actor a
 group by a.first_name 
  HAVING count(a.first_name) > 1

 

Output:

Basically, we've created  an extra  column  called duplicate Records that will tell us how many time  the name of Julio and the others names are repeated.

No comments:

Post a Comment