SELECT *
FROM(
comments
)
LEFT JOIN posts
点击posts
。id
= comments
。case_id
在哪里comments
。user_id
='8'
GROUP BY comments
。case_id
ORDER BY comments
。created_date
DESC我的编码就是这个。如何获得每篇文章的最新评论?同时将其分组显示第一条评论记录
答案 0 :(得分:0)
SELECT *
FROM ( SELECT comments.*
FROM comments
INNER JOIN comment2article USING (comment_id)
WHERE comment2article.article_d= ID_of_article
) MAIN_TABLE
LEFT JOIN ( SELECT comments.*
FROM comments
INNER JOIN comment2article USING (comment_id)
WHERE comment2article.article_d= ID_of_article
) DUMMY_TABLE ON (MAIN_TABLE.comment_id = DUMMY_TABLE.comment_id AND MAIN_TABLE.created < DUMMY_TABLE.created)
WHERE DUMMY_TABLE.comment_id IS NULL;
尝试以上查询。
希望这会对你有所帮助。