这不是之前做了一个磁力小站么.. 发现之前好多记录都是重复的(不要问我怎么发现的),就删除下,感觉不难,但总是写不对.. 这里纯粹记下sql.
select infohash from demo_magnet group by infohash having count(1) > 1;
//请注意:这里是全部删除,不会保留哈,一定要看仔细了...
delete from demo_magnet where infohash in (
select infohash from (
select infohash from demo_magnet group by infohash having count(1) > 1
) t
) ;
//注意哈,要带t(作为一个表)
delete from demo_magnet where infohash in (
select infohash from (
select infohash from demo_magnet group by infohash having count(1) > 1
) t
)
and id not in (
select dt.minid from (
select min(id) as minid from demo_magnet group by infohash having count(1) > 1
) dt
)
这里我的ID 是自增的可以使用这个。如果没有ID可以来判定怎么办?
delete from demo_magnet where infohash in (
select infohash from (
select infohash from demo_magnet group by infohash having count(1) > 1
) t
)
and _rowid not in (
select dt.minid from (
select min(_rowid) as minid from demo_magnet group by infohash having count(1) > 1
) dt
)
以上。
转载请注明出处: https://chrunlee.cn/article/mysql-delete-repeat-record.html