I have a users
table, a posts
table, and a search feature that queries MySQL for posts.
I want it to return all posts for 100 specific users (with a maximum of 6 posts per user).
I have a column called user_id
on the posts
table which is a foreign key.
Right now I can return all posts for those users like this:
SELECT id FROM posts WHERE user_id IN (1,2,3,4 .... 98,99,100);
However many of these users have hundreds of posts. I want to cap it at 6 per user. How can I add such a constraint to my query?
I am using MySQL version 8.0.15