What will be the equivalent find statement of the following below ?
@mostviews = Post.find_by_sql("select posts.id,posts.title from posts inner join countpages on countpages.post_id = posts.id order by countpages.counts desc limit 5")
@temp = Post.find_by_sql("SELECT posts.id,posts.title, comment_count.count FROM posts INNER JOIN (SELECT post_id, COUNT(*) AS count FROM comments GROUP BY post_id) AS comment_count ON comment_count.post_id = posts.id ORDER BY count DESC LIMIT 5;")
Is it possible to get the same result using find or where function ?
This assumes countpage is an association. Otherwise, you can be more explicit in the joins (“INNER JOIN…”)