php mysql Group By to get latest record, not first record

前端 未结 5 682
醉话见心
醉话见心 2020-12-05 15:04

The Table:

(`post_id`, `forum_id`, `topic_id`, `post_time`) 
(79, 8, 4, \'2012-11-19 06:58:08\');
(80, 3, 3, \'2012-11-19 06:58:42\'),
(81, 9, 9, \'2012-11-1         


        
5条回答
  •  借酒劲吻你
    2020-12-05 15:28

    try something like

    SELECT post_id, forum_id, topic_id 
    FROM   (SELECT post_id, forum_id, topic_id
            FROM posts
            ORDER BY post_time DESC) 
    GROUP BY topic_id 
    ORDER BY topic_id desc
    LIMIT 0,5
    

    change the order by and limit as needed.

提交回复
热议问题