[英] Getting top 3 rows for each ID in a list
I have this SQL query to get related comments for each ID in a list:
SELECT comments.id, comments.body, comments.created_at , comments.like_count, comments.post_id FROM comments WHERE comments.is_active AND comments.is_show AND comments.post_id in (1, 7, 9, 11, 3) GROUP BY comments.id ORDER BY comments.id LIMIT 3 <----- this is not working correctly!
I want to get the top 3 comments for each post id in the given list (1, 7, 9, 11, 3).
How to achieve this?