Q:

Mysql MIN() not returning min value on another column

I have two mysql tables topics and posts, the engine is InnoDB, and there are many posts with one topic_id, and I have a simple query like this:
select post_id, MIN(post_time) AS post_time from test1_posts where topic_id=19;

I would expect it return the post_id which has the minimum post_time, and in most cases, it does. 
My question is, under what circumstances, it will NOT return the post_id which has the minimum post_time?
If you need more information, please leave a comment.

A:

There is no guarantee that it will always return post_id corresponding to minimum post_time, because MySQL stores data as an unordered data-set; and post_id is not being processed under any aggregation function. 
Only time when you can be 100% sure is that you have only one post for the given topic_id
You should rather order your data based on post_time in ascending order and use LIMIT 1 to find the row corresponding to minimum post_time. Check the following: 
SELECT post_id, post_time 
FROM test1_posts 
WHERE topic_id = 19 
ORDER BY post_time ASC 
LIMIT 1

