2016 - 2024

感恩一路有你

数据库查询去除重复数据 Mysql如何去掉数据库中的重复记录?

浏览量:1274 时间:2021-03-16 16:14:23 作者:admin

Mysql如何去掉数据库中的重复记录?

很简单 通过id删除

DELETE

FROM

table_name AS ta

WHERE

ta.唯一键 <> (

SELECT

t.maxid

FROM

( SELECT max( tb.唯一键 ) AS maxid FROM table_name AS tb WHERE ta.判断重复的列 = tb.判断重复的列 ) t

)

Mysql数据库中多条重复数据,如何只删除一条?

列出要保留的记录ID,可以把这个结果写到一个临时表t1中: SELECT MAX(id) AS max_id FROM pedigree GROUP BY number然后:DELETE FROM pedigree WHERE id NOT IN (SELECT id FROM t1)也就是:delete from pedigree where id not in(select * from pedigree where group by number)。pedigree where id not in(select max(id) from pedigree where group by number having count(id) > 0) 查询结果是否符合删除要求!

数据库查询去除重复数据 去除重复数据 mysql去重复 保留一条

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。