Blog tutorial

Post here is you are having problems with any of the tutorials.
Post Reply
wignall6
Posts: 38
Joined: Thu May 05, 2011 8:05 pm

Blog tutorial

Post by wignall6 »

Hi,

Could someone please tell me when is wrong with this MYSQL query.
SELECT
				`problem`.`problem_id` AS `id`,
				`problem`.`problem_title` AS `title`,
				LEFT(`problem`.`problem_body`, 512) AS `preview`,
				`problem`.`problem_user` AS `user`,
				DATE_FORMAT(`problem`.`problem_date`, '%d/%m/%Y %H:%i:%s') AS `date`,
				`comments`.`total_comments`,
				DATE_FORMAT(`comments`.`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment` 
			FROM `problem`
			LEFT JOIN (
				SELECT
					`problem_id`,
					COUNT(`comment_id`) AS `title_comments`,
					MAX(`comment_date`) AS `last_comment`
				FROM `comments`
				GROUP BY `problem_id`
			) AS `comments`
			ON `problem`.`problem_id` = `comments`.`problem_id`
			ORDER BY `problem`.`problem_date` DESC
When I run it I get the error: "#1054 - Unknown column 'comments.total_comments' in 'field list'"

I have renamed posts to problem just to let you know and the code is right in all that.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Blog tutorial

Post by jacek »

It should be title_comments not total_comments.
Image
Post Reply