Using AND?OR in a MySQL Query
Posted: Sat Nov 04, 2006 12:07 pm
Hello All,
I have been trying to get a script to come up with the total number of comments a news item has under it
news
-------
id
author
posted
title
text
news_comments
----------
id
nid
poster
posted
comment
And I am using this query:
SELECT n.id as id, n.author as author, n.posted as date, n.title as title, n.text as text, COUNT(c.id) as num_comments FROM news as n, news_comments as c WHERE n.id = c.nid GROUP BY n.id LIMIT 10
Of course that doesnt work because it only shows news entries that have comments, Ive been playing with using 2 queries but I havent found an efficiant way of doing it.
Thanks for all advice!
I have been trying to get a script to come up with the total number of comments a news item has under it
news
-------
id
author
posted
title
text
news_comments
----------
id
nid
poster
posted
comment
And I am using this query:
SELECT n.id as id, n.author as author, n.posted as date, n.title as title, n.text as text, COUNT(c.id) as num_comments FROM news as n, news_comments as c WHERE n.id = c.nid GROUP BY n.id LIMIT 10
Of course that doesnt work because it only shows news entries that have comments, Ive been playing with using 2 queries but I havent found an efficiant way of doing it.
Thanks for all advice!