MySQL - how to show the latest topic per thread

前端 未结 2 795
遥遥无期
遥遥无期 2021-01-07 10:00

I am trying to create SQL for retrieveing a list of latests posts for the forum thread. I have the following code:

SELECT
 item_discuss_thread_id
 , item_dis         


        
2条回答
  •  庸人自扰
    2021-01-07 10:32

    Try this.

    SELECT
      *
    FROM
      (SELECT item_discuss_thread_id, item_discuss_post_title, COUNT(item_discuss_thread_id) AS nb_posts
       FROM item_discuss_posts
       ORDER BY __datecolumn__)
      AS ordered_by_date
    GROUP BY
      ordered_by_date.item_discuss_thread_id
    

    Replace __datecolumn__ with the column that stores posting time.

提交回复
热议问题