开发者

SQL syntax error in sql query

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.idAScategory_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`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜