homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Select from 3 tables
Any ideas how to optimize this query?
sunroof




msg:3818072
 9:12 pm on Jan 2, 2009 (gmt 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.

TABLES STRUCTURE:

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

Thaaaaaanks a lot.

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved