mysql怎么获取不重复的数据?

韩昊杰
2022-06-19 / 0 评论 / 83 阅读 / 正在检测是否收录...

mysql怎么获取不重复的数据?

mysql获取不重复的数据的方法:

在查询语句中添加distinct关键字来过滤重复的记录

select distinct 字段名 from 数据表;

使用方法

  • 对单个字段进行去重sql:

    select distinct  age from user;
  • 对多个字段进行去重sql:

    select distinct name,age from user;
  • 对多个字段进行去重并求count的sql:

    select count(distinct name,age) as total from user;
  • 也可以对select * 进行去重

    select distinct * from user;
0

评论 (0)

取消