I am really having a trouble figuring this one out.
I have a table 'Comments':
cmt_id (primary key, auto incr), thread_id, cmt_text
And I have these records in it:
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.
I want to now, get the minimum cmt_id
record in EACH thread. So, I did an aggregation query this way:
SELECT cmt_id, thread_id, cmt_text, MIN(cmt_id) FROM comments
GROUP BY thread_id;
However, I end up with this:
cmt_id thread_id cmt_text MIN(cmt_id)
5002 1251035762511 Alright, I second this. 5001
5003 1251036148894 Yet another comment. 5003
For the thread with thread_id
"1251035762511", I am always getting the comment with cmt_id
5002 as the record with minimum comment id.. I even tried inserting new records, cmt_id
5002 always comes as MIN and not the record with cmt_id
5001.