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 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...) 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. 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
Archived
This topic is now archived and is closed to further replies.