我正在建立一个基本论坛,我想获取创建的线程列表,但也most recent post
从帖子表中获取,以便我可以显示last reply and time of last reply
我的尝试如何导致重复的结果,我尝试了 aLEFT JOIN
和 aINNER JOIN
的结果相同。我希望有人知道解决方案。
这是我的尝试:
SELECT t1.username as thread_starter,
t2.username as last_reply_username,
t1.thread_time as thread_start,
t2.post_time as last_reply_time,
t1.title,
t1.sticky
FROM threads t1
INNER JOIN posts t2
ON t1.id = t2.threadid
ORDER BY t1.sticky DESC, t2.post_time DESC
有谁知道我如何解决这个问题,所以它只会从与每个线程相关的帖子表中获取最后和最近的帖子,而不返回重复的线程?