mySQL JOIN LEFT 不起作用?
我有两个表:tweets(包含 tweet_id 列的 ao)和 references(包含 tweet_id 和 class_id 列)。尚未为所有推文分配 class_id。我期望这能够提取推文的所有信息,包括其 class_id (如果已设置):
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
但是,我不断收到错误
#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
,我不明白错误来自何处。我已经根据 MySQL 文档(http://dev.mysql.com/doc/refman/5.0/en/left-join-optimization.html)构建了查询,但我可能遗漏了一些东西?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此:
References
是保留字,因此必须用反引号括起来。查看此链接以获取以下列表所有保留字。
Use this:
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.
REFERENCES
是一个 SQL 保留字,因此您需要使用引号:顺便说一句,SO 将您的
references
单词标记为蓝色,这应该会给您一个线索。REFERENCES
is an SQL reserved word, so you need to use quotes :By the way, SO colors your
references
word in blue, this should give you a clue.References是MySQL的保留字
references is a reserved word of MySQL