ZKX's LAB

mysql 取重复数据 mysql删除重复数据

2021-04-27知识5

mysql删除重复数据 选择重复数据 只保留一条 比如取id最小的一条delete table1 where[id]not in(select min([id])from table1group by(createtime))

在mysql数据库中如何让某个字段有重复的只取一条 select*from table#where not existsselect*from table#where#and#在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是 distinct只能返回它的目标字段,而无法返回其它字段,这个问题让我困扰了很久,用distinct不能解决的话,只有用二重循环查询来解决。给个例子把,比如:表table_a 4条数据id A B C D01 ab 1a2 1b2 12102 ab 2a3 3b3 4a103 ac 1a2 1b2 12104 ac 2a4 3b2 52g何让A字段重复取条 比01 ab 1a2 1b2 12103 ac 1a2 1b2 121保留相同A值id行select*from table_a awhere not existsselect 1 from table_a bwhere b.A=a.Aand b.id

mysql 查找出重复数据 然后把删除重复的数据 保留最新的一条 delete from `mygame_article` where title in(select title from `mygame_article` group by id having count(title)>;1)and id not in(select max(id)from `mygame_article` group by title having count(title)>;1);随手写2113了个,前半句是选择title重复的数据,后5261半句是剔除4102id最大的,delete是删除的意思。1653应该 思路是没问题的,这边不方便帮您测试

随机阅读

qrcode
访问手机版