0

I have two tables: tweets (a.o. containing column tweet_id) and references (containing columns tweet_id and class_id). Not all tweets might have been assigned a class_id yet. I was expecting this to work to extract all information of a tweet inclusing its class_id (if it has been set):

SELECT t.*, r.class_id FROM tweets t LEFT JOIN references r ON (t.tweet_id = r.tweet_id) ORDER BY t.tweet_id DESC LIMIT 50 

However, I keep getting an 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 'references r ON (t.tweet_id = r.tweet_id) ORDER BY t.tweet_id DESC LIMIT 50' at line 1 

I don't understand where the error is coming from. I have build the query according to the MySQL documentation (http://dev.mysql.com/doc/refman/5.0/en/left-join-optimization.html) but I am probably missing something?

3 Answers 3

2

Use this:

SELECT t.*, r.class_id FROM tweets t LEFT JOIN `references` r ON (t.tweet_id = r.tweet_id) ORDER BY t.tweet_id DESC LIMIT 50 

References is a reserved word, so it must be enclosed with backticks.
Take a look at this link to have a list of all reserved words.

Sign up to request clarification or add additional context in comments.

Comments

0

REFERENCES is an SQL reserved word, so you need to use quotes :

SELECT t.*, r.class_id FROM tweets t LEFT JOIN `references` r ON ... 

By the way, SO colors your references word in blue, this should give you a clue.

Comments

0

references is a reserved word of MySQL

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.