You need a subquery for the last column for each author and order from postid DESC. Then attach this result to the posts table:
SELECT B.* FROM ( SELECT * FROM ( SELECT userid,MAX(postid) postid FROM posts GROUP BY userid ) AA ORDER BY postid DESC LIMIT 10 ) A INNER JOIN posts B USING (user_id,post_id);
Make sure you have this index
ALTER TABLE posts ADD INDEX user_post_ndx (userid,postid);
RolandoMySQLDBA
source share