Jump to content

[SOLVED] How to work COUNT in a WHERE clause


phpknight

Recommended Posts

Sorry about that.  I'll try to be clearer.  I don't think those examples touched this.  Here is what I want to do.  I know it does not work and probably involves a subquery, but hopefully this will make the issue clear at least.

 

A real world example.  Let's say I wanted to group books by author.  However, I only wanted to see the authors that have written at least ten books. 

 

SELECT *, COUNT(book_ID) FROM table WHERE COUNT(book_ID)>10 GROUP BY author_ID

 

Of course, I can limit the result to 15 or 20 authors, but I cannot figure out how to limit the result to those authors who have only written x books or more.

 

It depends if you got all the info in one table or not. A subquery maybe necessary if dealing with multiple tables.

 

The last query example using "HAVING" will do it for you:

 

http://www.phpfreaks.com/forums/index.php/topic,179091.msg797633.html#msg797633  (same one as posted above)

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.