Created
January 24, 2014 07:09
-
-
Save hfhimage/8593316 to your computer and use it in GitHub Desktop.
mysql 删除重复数据
mysql 4 不支持嵌套的删除语法, 因此得需要通过创建临时表绕过
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS tmp_dels; | |
CREATE TABLE tmp_dels AS SELECT subscribe_tags.id FROM subscribe_tags, ( SELECT max(id) AS id, nick, tag_id FROM subscribe_tags GROUP BY nick, tag_id HAVING count(1) > 1 ) t WHERE subscribe_tags.nick = t.nick AND subscribe_tags.tag_id = t.tag_id AND subscribe_tags.id < t.id; | |
DELETE FROM subscribe_tags WHERE id IN (SELECT id FROM tmp_dels); | |
DROP TABLE IF EXISTS tmp_dels; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment