#1064 - Problem with SQL Syntax :(

Post here if you need help with SQL.
Post Reply
xFuSaiH
Posts: 2
Joined: Sat Jul 07, 2012 4:54 pm

#1064 - Problem with SQL Syntax :(

Post by xFuSaiH »

Hello guys. I have been following a tutorial on PHP Blog...

Now when I put this code
SELECT
				'posts'.'post_id' AS 'id',
				'posts'.'post_title' AS 'title',
				LEFT('posts'.'post_body', 512) AS 'preview',
				'posts'.'post_user' AS 'user',
				DATE_FORMAT('posts'.'post_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 'posts'
			LEFT JOIN (
				SELECT
					'post_id',
					COUNT('comment_id') AS 'total_comments',
					MAX('comment_date') AS 'last_comment'
				FROM 'comments'
				GROUP BY 'post_id'
			) AS 'comments'
			ON 'posts'.'post_id' = 'comments'.'post_id'
			ORDER BY 'posts'.'post_date' DESC
to SQL in my Database to check for syntax I get this back
#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 '.'post_id' AS 'id', 'posts'.'post_title' AS 'title', LEFT('posts'.'post_' at line 2
I really want this blog to happen, so can anyone here please help me ? It would be much appreciated.

Thanks a lot in advance

Patryk
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: #1064 - Problem with SQL Syntax :(

Post by jacek »

You have quotes around your column names, they should be backticks --> `
Image
xFuSaiH
Posts: 2
Joined: Sat Jul 07, 2012 4:54 pm

Re: #1064 - Problem with SQL Syntax :(

Post by xFuSaiH »

Thank You very much sir :)

I am ashamed of myself now...

Hope I will make this blog, thanks a lot again :)
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: #1064 - Problem with SQL Syntax :(

Post by jacek »

It's a very common mistake so don't feel too bad ;)
Image
Post Reply