It's time to implement sorting on my blog-like web application. In addition to browsing by creation date, I want users to be able to sort by the number of replies, too.
Given that I have two tables blog_posts and replies, and that replies has a field called blog_post_id (a foreign key for the blog_post it's a reply to), how do I write this query?
"Select the 30 blog posts with the most replies, sorted by the number of replies for each blog post in descending order."
I also want to paginate this. Will it be hard to get the next 30, the next 30, etc.?
My feeling is that this isn't too hard to do with SQL, I just don't know how to do it (still learning).