mysql - How to change this SQL so that I can get one post from each author? -
in sql below have last 5 posts. these posts same author. want select last 5 1 per author.
select `e` . * , `f`.`title` `feedtitle` , `f`.`url` `feedurl` , `a`.`id` `authorid` , `a`.`name` `authorname` , `a`.`about` `authorabout` `feed_entries` `e` inner join `feeds` `f` on e.feed_id = f.id inner join `entries_categories` `ec` on ec.entry_id = e.id inner join `categories` `c` on ec.category_id = c.id inner join `authors` `a` on e.author_id = a.id group `e`.`id` order `e`.`date` desc limit 5
edited
i've ended it:
select a.id, e.date, e.title, a.name feed_entries e, authors e.author_id =a.id order e.date desc limit 5
in query, how can 1 post each author?
what about
select a.id, a.name, e.date, e.titulo feed_entries e inner join authors on e.author_id = a.id -- recent feed_entry , e.date = (select max(e1.date) feed_entries e1 e1.author_id = a.id) order e.date desc
i haven't tested work.
Comments
Post a Comment