* Torkil Johnsen
> This works PERFECTLY
> Except:
> If an article has NO comments, it is not returned!

Use a LEFT JOIN:

SELECT a.title,a.date,a.author,a.summary,COUNT(c.id) as comments
   FROM articles as a
   LEFT JOIN article_comments as c ON
     a.id = c.article_id
   GROUP BY a.title,a.date,a.author,a.summary
   ORDER BY a.date DESC
   LIMIT 3

This also eliminates the WHERE clause in this case, as the criteria is used
in the ON clause of the LEFT JOIN.

<URL: http://www.mysql.com/doc/J/O/JOIN.html >

--
Roger



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to