开发者

SQL syntax error in sql query

开发者 https://www.devze.com 2023-04-06 10:15 出处:网络
I have this query: SELECT `post`.`id` AS `posts_id, `categories`.`id` AS `category_id`, `title`, `contents`,

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

精彩评论

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