DELETE FROM `mytbl` INNER JOIN ( SELECT 1 FROM `mytbl` GROUP BY `duplicated_column` HAVING COUNT(*)=2 ) USING(`id`)
Edit:
My bad, the above request will not work.
Assuming table structure:
id int auto_increment
num int # <is a column with duplicate values
The following query will work in MySQL (I checked):
DELETE `mytbl` FROM `mytbl` INNER JOIN ( SELECT `num` FROM `mytbl` GROUP BY `num` HAVING COUNT(*)=2 ) AS `tmp` USING (`num`)
The query will delete rows with 2 (no more) duplicate values ββin the num column.
Edit (again):
I suggest adding a key to the num column.
Edit (# 3):
If the author wanted to remove duplicate rows, for MySQL (this worked for me), the following should work:
DELETE `delete_duplicated_rows` FROM `delete_duplicated_rows` NATURAL JOIN ( SELECT * FROM `delete_duplicated_rows` GROUP BY `num1` HAVING COUNT(*)=2 ) AS `der`
Provided that the structure of the table is as follows:
CREATE TABLE `delete_duplicated_rows` ( `num1` tinyint(4) DEFAULT NOT NULL, `num2` tinyint(4) DEFAULT NOT NULL ) ENGINE=MyISAM;
Dor
source share