MySQL Forums
Forum List  »  Knowledge Base

Complex COUNT query
Posted by: Ashley Blurton
Date: February 20, 2009 09:43AM

I'm currently building a search for an application I am making. And because the tables are linked together a lot I can't seem to find out how to get how many results would be found.

What I want to do is search the table for entries that have no associated entries. In this it's blog posts, with no comments linked to them. I have found out how to get the entries themselves, but not how many without just grabbing the results without a limit and just counting the rows returned.

Here's my query for selecting the results:

SELECT b.*, COUNT(c.id) as count FROM blogs as b
LEFT JOIN comments as c ON (c.blog_id = b.id)
GROUP BY b.id
HAVING count = 0;

Options: ReplyQuote


Subject
Views
Written By
Posted
Complex COUNT query
4798
February 20, 2009 09:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.