Jump to content
xisto Community
alexviii

Using And?or In A Mysql Query

Recommended Posts

hi everyone, 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. 10x

Edited by alexviii (see edit history)

Share this post


Link to post
Share on other sites

Ya LEFT JOIN it.Well the main feature of LEFT JOIN is that if the table that is being joined is empty with regards to a particular row(here your news item) it will add the table with the same fields but with the value NULL that is treated as false of empty in PHP

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.