mysql - Most recent X posts by unique authors -
i have blog multiple authors can post. on frontpage want show carousel of recent x posts - let's 5. however, want filter out author duplicates. if author have multiple posts within 5, recent 1 make in , others filtered out. also, want select entire row, not ids. here example:
data
id | title | authorid | date 1 | "now" | 6 | 2013-03-27 2 | "this" | 5 | 2013-03-26 3 | "is" | 4 | 2013-03-27 4 | "the" | 2 | 2013-03-28 5 | "story" | 2 | 2013-03-29 6 | "all" | 4 | 2013-04-01 7 | "about" | 2 | 2013-04-02 8 | "how" | 3 | 2013-04-03 9 | "my" | 1 | 2013-04-04 10 | "life" | 1 | 2013-04-05 desired result
id | title | authorid | date 10 | "life" | 1 | 2013-04-05 8 | "how" | 3 | 2013-04-03 7 | "about" | 2 | 2013-04-02 6 | "all" | 4 | 2013-04-01 2 | "this" | 5 | 2013-03-26 i use following:
select * posts order date desc limit 5 but of course gets me following result
id | title | authorid | date 10 | "life" | 1 | 2013-04-05 9 | "my" | 1 | 2013-04-04 8 | "how" | 3 | 2013-04-03 7 | "about" | 2 | 2013-04-02 6 | "all" | 4 | 2013-04-01 and want eliminate duplicates. how?
i saw there distinct clause select author ids , want select entire row.
i think you're looking for:
select * (select * posts order date desc) p group p.authorid order date desc limit 5;
Comments
Post a Comment