0

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 to use near:

'categories.idAScategory_id,title,contents,date_posted,cat' at line 1

2
  • Please, make a more descriptive question title. Commented Sep 19, 2011 at 15:25
  • 2
    Don't expect us to click links we can't trust - post (the relevant part of) the query here instead. EDIT: Just like Tomalak has done for you. Commented Sep 19, 2011 at 15:26

2 Answers 2

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`
Sign up to request clarification or add additional context in comments.

Comments

1

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`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.