Forum Moderators: coopster

Message Too Old, No Replies

Purging duplicates from MySQL?

         

erikcw

1:40 am on May 14, 2006 (gmt 0)

10+ Year Member



Hi all,

I'm trying to purge duplicate records from my MySQL database. Are there any built in MySQL or php functions that can do this? If not, what is the best way to tackle the problem? It is a pretty large table (100,000+ records...)

Thanks!
Erik

eelixduppy

2:47 am on May 14, 2006 (gmt 0)



You could try something like this:


$sql = "select count(col1) as ccols,col1,col2 from table_1";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
if($row['ccols'] > 1) {
$newsql = "delete from table_1 where col1 = $row['col1'] and col2 = $row['col2] limit
$row['ccols']-1";
mysql_query($newsql);
}
}

You could try this; I haven't, but i hope it helps. Good luck!

eelix