一:最容易想到的就是关键字distinct
select distinct 字段名 from 表名
这个虽然简单但是有局限性,因为distinct只能放第一个,如果后面跟的字段很多,则根据所有字段去重(也就是如果后面俩字段则根据这俩字段去重,三个字段则根据这三个字段去重)
二:根据distinct和group by
select *, count(distinct 字段名) from 表名 group by 字段名
说明:group by 必须放在 order by 和 limit之前,不然会报错
三:根据not exists去重
select * from 表名 t where not EXISTS
(select 1 from 表名d where d.字段名= t.字段名 and d.字段名 >t.字段名)
not exists 是不存在,这也就是根据下面子查询过滤出唯一的那个数据进行查询出来