top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to delete duplicate records in MySQL or SQL?

+1 vote
558 views
How to delete duplicate records in MySQL or SQL?
posted Sep 5, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Following query first selects the duplicate rows and creates a temporary table temp and the deletes the duplicate rows.

DELETE FROM table_name  
where column_name in(
    SELECT  column_name 
        FROM (
                select column_name 
                FROM table_name
                GROUP BY column_A, column_B, column_C, ... 
                having COUNT(*)>1)temp
                );
answer Sep 5, 2014 by Amit Kumar Pandey
Similar Questions
0 votes

I wish to delete records in my database that is older than 3 months.

$todays_date = date('Y-m-d');
$old_records_to_delete = ???

if($old_records_to_delete)
{
include(connect.php);
$sql = "DELETE FROM table WHERE date >= '$old_records_to_delete'";
mysql_query($sql, $connect_db) or die(mysql_error());
}

...