Welcome to WebmasterWorld Guest from 54.205.130.92

Forum Moderators: open

Select from 3 tables

Any ideas how to optimize this query?

   
9:12 pm on Jan 2, 2009 (gmt 0)

5+ Year Member



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.

TABLES STRUCTURE:

blog_blogs (id, ...)
blog_posts (id, blog, published, date)
blog_galleries (id, post_id...)

Thaaaaaanks a lot.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month