数据模型

student表

  • 查询结果

id name
1 永远
2 诸叶
3 诸叶
4 刹那
5 刹那

单字段示例

SELECT
    id,name 
FROM
    student
WHERE
    name IN ( SELECT name FROM student GROUP BY name HAVING count( name ) > 1 )
查找表中多余的重复记录,重复记录是根据单个字段name来判断
  • 删除语句
DELETE 
FROM
    student
WHERE
    id NOT IN ( SELECT hd.minid FROM ( SELECT MIN( id ) AS minid FROM student GROUP BY name ) hd )

关注我的公众号SpaceObj 领取idea系列激活码

posted on 2023-05-10 17:31  张伯灵  阅读(28)  评论(0编辑  收藏  举报