In sql below, I have the last 5 posts. But sometimes these messages belong to one author. I want to select the last 5, but only one for the author.
SELECT `e` . * ,
`f`.`title` AS `feedTitle` ,
`f`.`url` AS `feedUrl` ,
`a`.`id` AS `authorId` ,
`a`.`name` AS `authorName` ,
`a`.`about` AS `authorAbout`
FROM `feed_entries` AS `e`
INNER JOIN `feeds` AS `f` ON e.feed_id = f.id
INNER JOIN `entries_categories` AS `ec` ON ec.entry_id = e.id
INNER JOIN `categories` AS `c` ON ec.category_id = c.id
INNER JOIN `authors` AS `a` ON e.author_id = a.id
GROUP BY `e`.`id`
ORDER BY `e`.`date` DESC
LIMIT 5
EDITED
I ended up with this:
SELECT a.id, e.date, e.title, a.name
FROM feed_entries e, authors a
WHERE e.author_id =a.id
ORDER BY e.date DESC
LIMIT 5
In this question, how can I get only one post for each author?
source
share