开发者

Mistakenly added duplicate records. How do I delete them?

开发者 https://www.devze.com 2023-02-13 02:57 出处:网络
EDIT This query is not working, any idea why? select `key`, distinct `filename`, `url`, `processed`, `timestamp` from snaps;

EDIT

This query is not working, any idea why?

select `key`, distinct `filename`, `url`, `processed`, `timestamp` from snaps;

It says to check syntax near 'distinctfilename``


I have the following table

CREATE TABLE IF NOT EXISTS `snaps` (
  `filename` varchar(255) COLLATE utf8_bin NOT NULL,
  `url` text COLLATE utf8_bin NOT NULL,
  `processed` int(11) NOT NULL,
 开发者_开发问答 `timestamp` int(11) NOT NULL,
  KEY `key` (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

I exported the rows of the table and mistakenly imported it back into the same table. So now I have two rows of everything. filename is unique.

How can I delete the duplicate records?


SELECT DISTINCT into a temporary table, flush the first one, and move them back again.


If you have all the original unduplicated rows of the table, can you not just

TRUNCATE <table> and then reimport them?


Does second set of rows has an identical timestamp from the insert? If so, you could DELETE based on that timestamp.

Alternately, you could SELECT INTO OUTFILE, delete the last half, TRUNCATE TABLE and then LOAD DATA INFILE.

0

精彩评论

暂无评论...
验证码 换一张
取 消