brown2005 Posted May 19, 2009 Share Posted May 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/158744-deleting-multiple-emails-in-mysql/ Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 $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...) Quote Link to comment https://forums.phpfreaks.com/topic/158744-deleting-multiple-emails-in-mysql/#findComment-837222 Share on other sites More sharing options...
brown2005 Posted May 19, 2009 Author Share Posted May 19, 2009 thank you. works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/158744-deleting-multiple-emails-in-mysql/#findComment-837246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.