热线电话:13121318867

登录
2019-01-17 阅读量: 776
MySQL去重查询distinct

table表如下:

id name

1 a

2 b

3 c

4 c

5 b

1、select distinct name from table

----------

name

a

b

c

2、select distinct name, id from table

----------

id name

1 a

2 b

3 c

4 c

5 b

distinct同时作用了两个字段

3、select id, distinct name from table

----------

出错

注:distinct必须放在所有字段之前

4、select *, count(distinct name) from table group by name

----------

id name count(distinct name)

1 a 1

2 b 1

3 c 1

注:这样就能去掉重复name的字段,且只会匹配出第一个出现的结果

2.9470
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子