mySQL JOIN LEFT 不起作用?

发布于 2024-12-15 21:38:52 字数 716 浏览 0 评论 0原文

我有两个表: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

做个ˇ局外人 2024-12-22 21:38:52

使用此:

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 是保留字,因此必须用反引号括起来。
查看此链接以获取以下列表所有保留字。

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.

烟花易冷人易散 2024-12-22 21:38:52

REFERENCES 是一个 SQL 保留字,因此您需要使用引号:

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

顺便说一句,SO 将您的 references 单词标记为蓝色,这应该会给您一个线索。

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.

憧憬巴黎街头的黎明 2024-12-22 21:38:52

References是MySQL的保留字

references is a reserved word of MySQL

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文