phpknight Posted January 28, 2008 Share Posted January 28, 2008 Hi, I am doing an query with count(*) in it but I also want to limit the results to where count(*) is >9 for instance. I know there must be some kind of dependent query to do this, but I cannot quite figure it out. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
toplay Posted January 28, 2008 Share Posted January 28, 2008 Your post is not clear. Maybe these links will help you: http://www.phpfreaks.com/forums/index.php/topic,179213.msg798278.html#msg798278 http://www.phpfreaks.com/forums/index.php/topic,179091.msg797633.html#msg797633 http://www.phpfreaks.com/forums/index.php/topic,129174.0.html Quote Link to comment Share on other sites More sharing options...
phpknight Posted January 28, 2008 Author Share Posted January 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
toplay Posted January 28, 2008 Share Posted January 28, 2008 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) Quote Link to comment Share on other sites More sharing options...
phpknight Posted January 28, 2008 Author Share Posted January 28, 2008 toplay, Thanks! I just read something about that, too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.