我有一个简单的文章和评论系统,其中包含下表:
文章表:
ID | Writer | Text
1 | Bob | good article
2 | Marley | read this
评论表:
ID | Article_ID | Comment
1 | 1 | i love this article
2 | 1 | good one
3 | 2 | waiting for more
我想选择每篇文章及其下方的评论。我使用以下查询:
SELECT * FROM articles LEFT JOIN comments ON articles.ID = comments.Article_id
预期结果:
Article 1: good article
Comments: 1 - i love this article
2 - good one
Article 2: read this
Comments: 3 - waiting for more
我得到什么:
Article 1: good article
Comments: 2 - good one
Article 2: read this
Comments: 3 - waiting for more
那么如何选择每篇带有评论的文章,并按 id 降序排列文章,以及按 id 降序排列评论?
谢谢