我真的很难找出这一个。由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.