I have a blog where multiple authors can post. On the frontpage I want to show a carousel of the most recent X posts - let's say 5. However, I want to filter out author duplicates. So if an author would have multiple posts within those 5, only the most recent one would make it in and the others would be filtered out. Also, I want to select the entire row, not just IDs. Here an 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 currently use the following:
SELECT * FROM posts
ORDER BY date DESC
LIMIT 5
But of course this gets me the 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 I want to eliminate the duplicates. How?
I saw that there is a DISTINCT clause but this would select only the author IDs and I want to select the entire row.