I have 5 categories. I want to query each category and get a list of the most recent posts from them. I also only want single post from each category, with no duplicates. Is there a way to do this without writing 5 queries? Can it be done with one query?
I should end up with the following results:
1|most recent post from CategoryA
2|most recent post from CategoryB
3|most recent post from CategoryC
4|most recent post from CategoryD
5|most recent post from CategoryE
Here is some code I used for the front page of this site. It pulls one post (I chose a random post) from each category and displays some of the post content. I’ve included the HTML so you can make sense of it.