Re: SQL Join query

From: Date: Sat, 07 Aug 2004 15:59:16 +0000
Subject: Re: SQL Join query
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-193086@lists.php.net to get a copy of this message
Raditha Dissanayake wrote: > try postgres instead http://www.postgresql.org/ It's the most helpful comment I've seen for a long time. You know, it won't work in Postgre too probably. If you like Postgre - use it and don't force others to use it (for wrong reasons nevertheless). Everyone should pick his/her own tools... Anyway, instead of writing this: 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; Write this: SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics LEFT JOIN pic_comments ON (pic_comments.pic_id = pics.id) WHERE pics.category = 1 GROUP BY pics.pic_id; Lenar

« previous php.general (#193086) next »