Let's say I have a database table (posts) with fields ID, Msg and time_id
. A user (ID) can post any number of messages.
I can extract the last 15 messages by:
SELECT * FROM posts ORDER BY time_id DESC LIMIT 0,15
Because a user can post unlimited messages, I need to avoid displaying too many messages from one user, so I want to LIMIT to a maximum of 3 posts from one user but still fetch 15.
How do I fetch last 15 recent messages and ensure that I get a maximum of three from any user who might have more that 3 posts in the recent 15 messages