2019-01-17
閱讀量:
837
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
注:這樣就能去掉重復(fù)name的字段,且只會匹配出第一個出現(xiàn)的結(jié)果






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論
0條評論