Mattias Jönsson wrote:

SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics, pic_comments WHERE pics.category = 1 AND pics.id = pic_comments.pic_id GROUP BY pic_comments.pic_id;
[snip]
The problem is that i only get the the pictures that have comments, i want even the pictures where there arent no comments and the field num_comments should be 0.

Need a LEFT JOIN

SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics LEFT JOIN pic_comments on pics.id = pic_comments.pic_id WHERE pics.category = 1 GROUP BY pic_comments.pic_id

--

John Holmes

php|architect - The magazine for PHP professionals - http://www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to