Let’s say that we have a users table, and a user can have many posts (posts have the user_id column).
I want to retrieve posts for the first 5 users, but only one post per user. So, at the end I want to have 5 posts, where each post belongs to a different user. How can I do that in SQL?
You should have two tables
And now to retrieve all user with one post for each
If you want to get the oldest post for each user
And for latest post use MAX(post_id) instead of MIN(post_id)