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

Why php is used with mysql?

532


Is php 7.0 stable?

511


How to call a php function from html button?

611


What is php full form?

553


Are php session secure?

530






What is stdclass in php?

548


Tell me what does the php error 'parse error in php - unexpected t_variable at line x' means?

563


Which programming language does php resemble?

539


Where do I run php code?

529


Tell me what is the difference between the functions strstr() and stristr()?

535


Which php mvc framework is best?

568


Explain how to submit form without a submit button.

545


What is an example of a variable?

546


in PHP for pdf which library used?

560


How variables are passed through arguments?

556