Loading...

用distinct在MySQL中查詢多條不重複記錄值

Temperature: 0 °C

ChungChung
author_tools


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

結果:

id name count(distinct name)
1 a 1
2 b 1
3 c 1

group by 必須放在 order by 和 limit之前,不然會報錯.
更簡單的解決方法:

select id, name from table group by name

台北市松山區八德路四段650號 Go

https://innstory.com/story-用distinct在MySQL中查詢多條不重複記錄值-115
寫程式筆記

Prev
 我在檳城

Next
CSS透明度 

Nearby Attractions

台北市松山區八德路四段650號-Nearby Attractions

  • 原大阪商船株式會社臺北支店 Go
  • 臺灣總督府交通局遞信部 Go
  • 國立臺灣大學日式宿舍-青田街... Go
  • 紫藤廬 Go
  • 興福庄建塚紀念碑 Go
  • 清真寺 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

網站植入Facebook登入FB.api請求修改

網站植入Facebook登入...

會特別紀錄下來的原因是因為FB.api請求又調整了~ function fblogin() {//開...

CentOS 5.2 使用 YUM 將 PHP 5.1.6 更新到 5.2.6

CentOS 5.2 使用 ...

CentOS 5. 版內建的 PHP 版本為 5..,甚至於 5. 版仍舊是 5.. 版本。 基於系...

RewriteRule仿靜態連結

RewriteRule仿靜態...

前幾天寫了關於頁面導向位置的定義。https://innst...

Recommended reading

Other stories happened at this address

Mysql最怕就是手賤

Mysql最怕就是手賤

今天我手賤了眼盲了@@... 錯把delete當成UPDATE....啃!!今天下午超不順的... ...

最愛的藝術文宣

最愛的藝術文宣

每次看到這些藝文文宣, 總會讓我想起以前在廣告公司上班的日子, 工作壓力雖然很大, 可是卻是做著自己...

意外的客人

意外的客人

今晚,我的水族箱裡來了一位嬌客,【豆娘】... s 我想,牠應該是前幾天去水族店買黑殼蝦時偷渡來的....

你是不是像我就算受了冷漠,也不放棄自己想要的生活。

你是不是像我就算受了冷漠,也...

累了就該充電一下,聽首好歌... 好歌總能激勵人心。 不寫,就會就永遠寫不完......寫了,遲早有...

Mysql 查詢時間區間是否包含特定日期

Mysql 查詢時間區間是否...

這其實只是一個簡單的問題,以前並不常用... 但這陣子寫的案子比較偏系統面,這樣的查詢問題變多了@@...

義大利麵

義大利麵

Mandy 喜歡吃麵食... 而最近她喜愛的麵食是義大利麵...一有機會就一直在我耳邊說著想吃......

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format