mysql删除重复记录

Solution 1:

Add Unique Index on your table:

ALTER IGNORE TABLE `TableA`
ADD UNIQUE INDEX (`member_id`, `quiz_num`, `question_num`, `answer_num`);

Solution 2:

Add primry key in your table then you can easily remove duplicates from your table using below query:

DELETE FROM member
WHERE id IN (SELECT *
             FROM (SELECT id FROM member
                   GROUP BY member_id, quiz_num, question_num, answer_num HAVING (COUNT(*) > 1)
                  ) AS A
            );

Solution 3:

SELECT DISTINCT * INTO TableA_Verify FROM TableA;

DROP TABLE TableA;

RENAME TABLE TableA_Verify TO TableA;

ref:

http://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql

http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql

http://stackoverflow.com/questions/14046355/how-do-i-delete-all-the-duplicate-records-in-a-mysql-table-without-temp-tables

http://www.databasejournal.com/features/mysql/article.php/10897_2201621_2/Deleting-Duplicate-Rows-in-a-MySQL-Database.htm

时间: 2024-10-16 22:59:50

mysql删除重复记录的相关文章

mysql 删除重复记录

mysql删除重复记录的原理是: 将需要比较的列放到group by后,取出主键的最小值,再删除不在这个临时表主键的行 命令行格式如下 delete from users  where id not in ( select id from ( select min(id)  from users group by name,sex )  as tmp); 需要比较的列是name和sex,取出id后再从users表中取出id查看该id是否在临时表中存在,不存在则删除掉.

Mysql删除重复记录,保留id最小的一条

mysql 查询重复字段,及删除重复记录的方法MySQL, 数据库, 数据库, 字段, 服务器数据库中有个大表,需要查找其中的名字有重复的记录id,以便比较.如果仅仅是查找数据库中name不重复的字段,很容易:SELECT min(`id`),`name` FROM `table` GROUP BY `name`; 但是这样并不能得到说有重复字段的id值.(只得到了最小的一个id值)查询哪些字段是重复的也容易:SELECT `name`,count(`name`) as count FROM `

mysql 删除重复记录语句

mysql 根据条件删除重复记录 只保留最小id的重复数据 DELETEFROM newsWHERE news_id IN ( SELECT a.news_id FROM ( SELECT news_id FROM news WHERE flag = 1 GROUP BY news_id HAVING count(news_id) > 1 ) a )AND posid NOT IN (SELECT b.posid from ( SELECT min(posid) as posid FROM ne

mysql删除重复记录语句的方法

例如: id name value 1 a pp 2 a pp 3 b iii 4 b pp 5 b pp 6 c pp 7 c pp 8 c iii id是主键 要求得到这样的结果 id name value 1 a pp 3 b iii 4 b pp 6 c pp 8 c iii 方法1 delete YourTable where [id] not in ( select max([id]) from YourTable group by (name + value)) 方法2 delet

MySQL删除重复记录只保留一条

删除表中重复记录,只保留一条: delete from 表名 where 字段ID in (select * from (select max(字段ID) from 表名 group by 重复的字段 having count(重复的字段) > 1) as b); 实例:2.当想要为某一个表建立一个唯一索引,由于表中有重复记录而无法进行时,需要删除重复记录.例表 dept id_no id_name 100 'AAA' 101 'BBB' 102 'CCC' 103 'DDD' 100 'EEE

MySQL删除重复记录的方法

参考网上的方法,总结了产出重复记录的方法,欢迎交流. 方法1:创建一个新表临时储存数据 假设我们有一个存在多个字段的表,表中有部分数据的若干字段重复,此时我们可以使用DISTINCT这个关键字对表数据进行筛选. 1 CREATE [TEMPORARY] TABLE temp LIKE origin_tb; 2 INSERT temp(attr1,attr2,...) SELECT DISTINCT attr1,attr2,... FROM origin_tb; 3 DELETE FROM ori

MYSQL 删除重复记录,只保留最大ID

table : productprice table column : id ,productAsin ... 同一个productAsin 只保留最近的那条,即只保留ID 最大的. 第一步: 查出有重复的记录和最大的id SELECT productAsin,MAX(id) maxId FROM productprice GROUP BY productAsin HAVING COUNT(id) >= 2)tempt 第二步:查出在重复记录的,并且小于最大的id SELECT productp

mysql删除重复记录,保存Id最小的一条

方法1: 1.创建一个临时表,选取需要的数据. 2.清空原表. 3.临时表数据导入到原表. 4.删除临时表. mysql> select * from student; +----+------+ | ID | NAME | +----+------+ | 11 | aa | | 12 | aa | | 13 | bb | | 14 | bb | | 15 | bb | | 16 | cc | +----+------+ 6 rows in set mysql> create temporar

Mysql 删除重复记录,只保留最小的一条

delete from `jb_postcontent` where id not in(select min(id) from (select * from `jb_postcontent`) as t group by t.id); 网上搜索的大部分都是如下这样 delete from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) and