Page 1 of 1

whats wrong with this query ??

Posted: Mon Jan 28, 2008 5:51 am
by PHPycho
Hello forums !!
I am getting problems in this query :

Code: Select all

 "SELECT IF(COUNT(*) > 0, COUNT(*), 0) AS total FROM table1 WHERE field1 = 'some_value' GROUP BY field2"
if there is no result the query is supposed to give 0 value but it gives nothing.
Can anbody help what went wrong in above query ?
thanks in advance to all of you

Re: whats wrong with this query ??

Posted: Mon Jan 28, 2008 8:32 am
by Oren
What's the point of the IF(...?
If there are no results, count() will give you 0 anyway.