Select all threads and order by the latest one

前端 未结 2 1443
醉酒成梦
醉酒成梦 2020-12-22 02:52

Now that I got the Select all forums and get latest post too.. how? question answered, I am trying to write a query to select all threads in one particular

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 03:19

    Forget the distinct on:

    SELECT t.id, u.username, p.updated_at, t.title
    FROM   forum_threads             t
    LEFT   JOIN forum_posts   p ON p.thread_id = t.id
    LEFT   JOIN users         u ON u.id = p.user_id
    WHERE t.forum_id = 3
    ORDER  BY p.updated_at DESC;
    

提交回复
热议问题