Do you have any ideas how to optimize this query for fastest performance? Using join or something else? SELECT DISTINCT(blog_galleries.post_id), COUNT(blog_galleries.post_id) AS howmany FROM blog_galleries, blog_posts, blog_blogs WHERE blog_posts.id=blog_galleries.post_id AND blog_posts.published='1' AND blog_posts.blog=blog_blogs.id AND blog_posts.date BETWEEN (NOW() - INTERVAL 1 YEAR) AND (NOW()) GROUP BY blog_galleries.post_id HAVING howmany>2
I have 3 tables (blog_galleries, blog_posts, and blog_blogs). I need to select all galleries which have more than 2 photos, which are associated to posts published within the last year.