Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Select from 3 tables

Any ideas how to optimize this query?

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

Junior Member

10+ Year Member

joined:Nov 8, 2005
votes: 0

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.


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

Thaaaaaanks a lot.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members