数据库处理重复数据只保留重复数据的第一条数据

CREATE table FavoritesTemp (SELECT t_right.id FROM ( SELECT min( CreationTime ) CreationTime, uid, mid, type, Status FROM Favorites GROUP BY uid, mid, type, Status ) t_left LEFT JOIN Favorites t_right ON t_left.CreationTime = t_right.CreationTime

1group by 就是重复分组
2我这个id是guid麻烦一点
将id存了新表中FavoritesTemp

DELETE
FROM
Favorites
WHERE
Id NOT IN (select id from FavoritesTemp )

你可能感兴趣的:(数据库处理重复数据只保留重复数据的第一条数据)