I needed to delete duplicate entries in MySql with PHP. After some trial and error I wrote a script that will do it for me. What I needed to do was delete duplicate email addresses in a email script. Here is the code that made that magic happen.  

 $result = $con->query("SELECT email FROM newsusers group by email having count(*) >= 2") ;
while ($row = $result->fetch_assoc()) {
   $orgemail=$row['email']; 
    echo $orgemail;
    echo '<br/>';
mysqli_query($con,"DELETE FROM newsusers WHERE email='$orgemail' ");
}


Sign Up To Comment