Write a query to to delete duplicate rows?

Answer Posted / rakesh dongarwar

$query="SELECT * FROM `emails` ORDER BY `email` ASC LIMIT 0, 30";
mysql_query($query);
$result=mysql_query($query);

$numrows=mysql_num_rows($result);

$totalemailsdeleted=0;
$i=1;
$i2=0;
while($i2 < $numrows)
{
$id=mysql_result($result, $i2, id);
$email=mysql_result($result, $i2, email);
while($i < $numrows)
{
$idcompare=mysql_result($result, $i, id);
$emailcompare=mysql_result($result, $i, email);
if($emailcompare == $email)
{
$query="DELETE FROM `emails` WHERE `id` = '$idcompare' LIMIT 1";
mysql_query($query);
$emailsdeleted.="$emailcompare<br>";
$totalemailsdeleted++;
$numrows=mysql_num_rows($result);
}
else
{
}
$i++;
}
$i2++;
}

Is This Answer Correct ?    4 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is csrf verification?

712


Which is the best web server?

690


What is session in c#?

715


What is "echo" in php?

710


What are form input html tags?

710


In PHP, fgets() is used to read a file one line at a time. State Whether True or False?

858


Describe PHP error and logging information?

737


What is the purpose of the '.frm' file extension? What do thes file contain?

689


Where are the persistent cookies stored on your computer?

760


How do you check if a variable has not been set in php?

681


What is a path Traversal?

718


Is uploaded file php?

704


What is a http session?

703


What is php trait?

700


What enctype is required for file uploads to work?

704