JoeHoldcroft
02-17-2007, 01:19 PM
Does anyone have any ideas what I'm doing wrong in this long, complex query? I'm querying it in PHP and basically I use it to display the latest news item, all the joins are so I can give the amount of comments and the category name that it's posted in.
This is the query:
SELECT news.*, news.id AS news_id, news.date AS news_date, news_categories.name AS cat_name, COUNT(news_comments.*) AS num_comments FROM news, news_categories, news_comments WHERE news.category_id = news_categories.id AND news_comments.news_id = news.id ORDER BY news.date DESC LIMIT 1
This is the error it returns when I view the page:
An error occured (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS num_comments FROM news, news_categories, news_comments WHERE news.category' at line 1
This is the query:
SELECT news.*, news.id AS news_id, news.date AS news_date, news_categories.name AS cat_name, COUNT(news_comments.*) AS num_comments FROM news, news_categories, news_comments WHERE news.category_id = news_categories.id AND news_comments.news_id = news.id ORDER BY news.date DESC LIMIT 1
This is the error it returns when I view the page:
An error occured (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS num_comments FROM news, news_categories, news_comments WHERE news.category' at line 1