whats wrong with this query ??

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

whats wrong with this query ??

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: whats wrong with this query ??

Post by Oren »

What's the point of the IF(...?
If there are no results, count() will give you 0 anyway.
Post Reply