RE: A small SQL query problem

2002-04-12 Thread Roger Baklund
* 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... :( [...] One

Re: A small SQL query problem

2002-04-12 Thread Torkil Johnsen
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

Re: A small SQL query problem

2002-04-12 Thread John Klein
[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

RE: A small SQL query problem

2002-04-12 Thread Roger Baklund
* 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