I have this query:
SELECT `post`.`id` AS `posts_id,
`categories`.`id` AS `category_id`,
`title`,
`contents`,
`date_posted`,
`categories`.`name
FROM `post`
INNER JOIN `categories` ON `categories`.`id` = `post`.`cat_id`
And it yields this error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t开发者_Python百科o use near:
'categories
.
idAS
category_id,
title,
contents,
date_posted,
cat' at line 1
You are missing backticks ` at various locations:
SELECT `post`.`id` AS `posts_id`, `categories`.`id` AS `category_id`,
`title`,`contents`,`date_posted`,`categories`.`name`
FROM `post`
INNER JOIN `categories` ON `categories`.`id` = `post`.`cat_id`
You have forgotten to end "`".
Try this:
SELECT `post`.`id` AS `posts_id`, `categories`.`id` AS `category_id`,
`title`,`contents`,`date_posted`,`categories`.`name`
FROM `post`
INNER JOIN `categories` ON `categories`.`id` = `post`.`cat_id`
精彩评论