Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Duplicate email addresses from Table in MYSQL

I have a table with columns for ID, firstname, lastname, address, email and so on.

Is there any way to delete duplicate email addresses from the TABLE?

Additional information (from comments):

If there are two rows with the same email address one would have a normal firstname and lastname but the other would have 'Instant' in the firstname. Therefore I can distinguish between them. I just want to delete the one with first name 'instant'.

Note, some records where the firstname='Instant' will have just 1 email address. I don't want to delete just one unique email address, so I can't just delete everything where firstname='Instant'.

Please help me out.

like image 724
fawad Avatar asked May 09 '11 10:05

fawad


People also ask

How do you remove duplicate emails in SQL?

Approach: Using DELETE and WHERE clause [Accepted] Email = p2. Email ; Then we need to find the bigger id having same email address with other records. So we can add a new condition to the WHERE clause like this.

How do I find duplicate emails in MySQL?

You can't directly do that in MySQL because there is no function to urlencode or urldecode strings. You will have to create a User Defined Function to handle that process. Once you have that function just go for a simple group by with a having clause.

How do I delete duplicate emails?

Holding the Ctrl key, select duplicate emails one by one manually; and then press the Delete key to remove them.


1 Answers

DELETE n1 FROM customers n1, customers n2 WHERE n1.ID > n2.ID AND n1.email = n2.email
like image 104
Alok Nath Avatar answered Oct 16 '22 10:10

Alok Nath