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

How is a session id generated?

530


The left association operator % is used in PHP for?

576


How many types of array supported in php?

530


How we get browser details of clients machine?

518


What is csrf verification?

529






Is age interval or ordinal data?

517


Where are cookies stored php?

502


What is php built on?

501


Why sessions are used in php?

506


How do you end a function in python?

534


Explain me what is the use of header() function in php?

619


How would you open a directory for reading in php?

568


What is the use of mvc in php?

512


Does php 7 support multiple inheritance?

513


What are the differences between php3 and php4 and php5? What is the current stable version of php? What advance thing in php7?

615