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
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...)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.