I'm writing a query in which i want to limit the number of rows by foreign key id.
To give you an example let's say i have a posts table and each post has anywhere from 0 to 100 comments.
Now right now I'm looping over all posts individually and then SELECT the comments for each post using a LIMIT 0,5.
What i want to do instead is just write one SELECT statement for reading all the comments using something like post_id IN (1,2,3,4...999)
but only load up to 5 comments per each post?
Edit: The postgres way of doing it can be found here. The mysql way of doing it is here