Re: SQL Join query
| From: | Peter Brodersen | Date: | Tue, 10 Aug 2004 09:28:57 +0000 |
| Subject: | Re: SQL Join query | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193251@lists.php.net to get a copy of this message | ||
Hi,
On Mon, 9 Aug 2004 18:12:42 +0000, in php.general you wrote:
>* Thus wrote Jonathan Haddad:
>> The only problem there is when you group the LEFT JOIN pictures that
>> have a count of 0 return a count of 1. Unfortunately there's no single
>> query that I figured out when I did this same project that would give
>> accurate results.
>
>SELECT
> pics.*,
> pic_comments.*,
> count(*) + if(pic_comments.pic_id = NULL, -1, 0)
Or simply:
SELECT
pics.*,
pic_comments.*,
count(pic_comments.pic_id)
..
COUNT() does not count fields with NULL when specifying a specific
field (as opposed to just count(*) )
.. but this is rather an SQL-related question.