Select 唯一且有限制

Select unique with limit

这是一个例子:

如您所见,前 4 条记录具有相同的 topic_id 编号。我如何获得具有唯一性的最后 10 条记录 topic_id?

谢谢。

PS 正确结果示例:

id        user_id    topic_id   ...
306114    14331      26164      ...
306110    14331      27001      ...
306109    14331      26660      ...
...       ...        ...        ...
SELECT posts.id, posts.user_id, posts.text, posts.topic_id, posts.updated_at, topics.name as topic_name, topics.forum_id FROM my_forum_posts AS posts
                      ...
                      WHERE posts.id IN (SELECT MAX(id) FROM my_forum_posts GROUP BY topic_id)
                      ORDER BY posts.id DESC LIMIT 10