Fetch last item in a category that fits specific criteria

Posted by Franz on Stack Overflow See other posts from Stack Overflow or by Franz
Published on 2010-04-26T17:42:54Z Indexed on 2010/04/26 17:53 UTC
Read the original article Hit count: 196

Filed under:
|
|
|

Let's assume I have a database with two tables: categories and articles. Every article belongs to a category.

Now, let's assume I want to fetch the latest article of each category that fits a specific criteria (read: the article does). If it weren't for that extra criteria, I could just add a column called last_article_id or something similar to the categories table - even though that wouldn't be properly normalized.

How can I do this though? I assume there's something using GROUP BY and HAVING?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql