Jump to content

Deleting Multiple Emails in mysql


brown2005

Recommended Posts

I have a table

 

emails

 

emails_id

emails_email

 

and what I want to do is delete records that have multiple emails_email in.

 

any help please?

 

and before anyone says stop this on registration, I have now done this, but just want to get rid of the duplicates I already have.

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/158744-deleting-multiple-emails-in-mysql/
Share on other sites

$get_emails = mysql_query("SELECT * FROM `emails`");
while($row = mysql_fetch_assoc($get_emails)){
     $curr_email = $row['emails_email'];
     $curr_count = mysql_query("SELECT * FROM `emails` WHERE `emails_email`='".mysql_escape_string($curr_email)."'");
     $i = mysql_num_rows($curr_count);
     while($i > 1){
          $del = mysql_query("DELETE FROM `emails` WHERE `emails_email`='".mysql_escape_string($curr_email)."' LIMIT 1");
          $i--;
     }
}

 

Run this once. This will delete duplicate entries in emails_email. (I suggest backing up first...)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.