Php how to delete duplicate records from mysql ??
Is there any way to delete duplicate records from mysql by php ???
if you are one who searching this in google, so answer is YES. how i will let you know. see this post below and you will do that easily.
select all database unique results
for select unique records we have to use this query, or group by
$qry = "select distinct name from tablename"; $db->query( $qry ); while( $data = $db->fetchArray() ) { $qry1 = "select * from tablename where name='".$data['name']."' "; $db1->query( $qry1 ); if($db1->numRows() > 1) { $check=0; while( $data1 = $db1->fetchArray() ) { if($check > 0) { ####### add delete query here $sql_del="delete from tablename where Id=".$data['Id']; $db->query( $sql_del ); } $check++; } } }
name = the field to check duplicate records
now select again same table with the name, and after that we check all unique records and only delete
records those greater than 1 of number rows.
coz 0 is the original 1st records and we have to keep it and delete similar other records.















January 14th, 2010 at 2:16 pm
Спасибо за коды.
July 26th, 2011 at 3:24 am
yes, you can delete duplicate record from mysql using single query..
ALTER IGNORE TABLE table_name ADD UNIQUE INDEX(col1,col2);
January 21st, 2012 at 8:08 pm
How to delete duplicate rows with SQL
http://www.xaprb.com/blog/2006/10/11/how-to-delete-duplicate-rows-with-sql/