我真的很難找出這一個。由MySQL混亂組
我有一個表「備註」:
cmt_id (primary key, auto incr), thread_id, cmt_text
而且我在裏面有這些記錄:
cmt_id thread_id cmt_txt
5002 1251035762511 Alright, I second this.
5003 1251036148894 Yet another comment.
5001 1251035762511 I am starting a thread on this.
我想現在,讓每個線程的最低cmt_id
記錄。所以,我做了一個彙總查詢是這樣的:
SELECT cmt_id, thread_id, cmt_text, MIN(cmt_id) FROM comments
GROUP BY thread_id;
不過,我結束了這一點:
cmt_id thread_id cmt_text MIN(cmt_id)
5002 1251035762511 Alright, I second this. 5001
5003 1251036148894 Yet another comment. 5003
對於thread_id
「1251035762511」的主題,我總是掌握cmt_id
5002評論作爲記錄與最小評論編號..我甚至嘗試插入新記錄,cmt_id
5002總是作爲MIN而不是記錄與cmt_id
5001.