* 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
[EMAIL PROTECTED] wrote:
>
> Thanks for the suggestion! I modified your query to something that works for
> me (I was inaccurate with the column names before, sorry... :)
>
> SELECT a.article_id,a.title,a.date,a.summary,COUNT(c.id) as comments
> FROM articles as a,article_comments as c
> WHERE a
Thanks for the suggestion! I modified your query to something that works for
me (I was inaccurate with the column names before, sorry... :)
SELECT a.article_id,a.title,a.date,a.summary,COUNT(c.id) as comments
FROM articles as a,article_comments as c
WHERE a.article_id = c.article_id
GROUP BY a.ar
* Torkil Johnsen
[...]
> I have no problems displaying the title, date, author, summary of the
> articles or anything. Its just doing an sql query that gets my 3 latest
> articles AND counts how many comments each article has, and doing
> it in ONE query instead of two separate ones... :(
[...]
>
A small SQL query problem concerning articles and article_comments :) You
experts will have no problem with this :)
In brief:
-
I have no problems displaying the title, date, author, summary of the
articles or anything. Its just doing an sql query that gets my 3 latest
articles AND