美文网首页
数据库表去重

数据库表去重

作者: 轻云之闭月 | 来源:发表于2018-03-30 19:23 被阅读19次

distinct

表示其后所有字段合并在一起去重,distinct必须放在最前面
如:
select distinct name, age from tb;
表示去除名字和年龄都相同的字段

指定列去重

利用分组和子查询

  • 去掉重复记录
    select * from student where id in (select Max(id) from student group by score)
    去除相同分数的学生数据

  • 获取重复记录
    select * from student where id not in (select Max(id) from student group by score)

相关文章

网友评论

      本文标题:数据库表去重

      本文链接:https://www.haomeiwen.com/subject/zmzicftx.html