php中mysql的左连接/外键问题
我有表队列和请求。队列的 reqID 是请求的 reqID 的外键。 两个表都有 vanID
我试图获取队列中的所有内容,以及队列引用的每个请求的所有信息。这是我的查询。
$sql = mysql_query("SELECT queue.*, requests.*
FROM queue
WHERE queue.vanID = '$vanID'
LEFT JOIN requests ON queue.reqID = requests.reqID
ORDER BY rank ASC") or die(mysql_error());
这是我收到的错误。
1064:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“LEFT JOIN requests ON queue.reqID = requests.reqID ORDER byrank ASC”附近使用的正确语法
,我似乎无法弄清楚,有什么帮助吗?
I have tables queue and requests. queue's reqID is a foreign key to requests' reqID.
both tables have vanID
I am trying to get all the stuff in queue, as well as all the information for each request that queue references. This is my query.
$sql = mysql_query("SELECT queue.*, requests.*
FROM queue
WHERE queue.vanID = '$vanID'
LEFT JOIN requests ON queue.reqID = requests.reqID
ORDER BY rank ASC") or die(mysql_error());
This the error I'm getting.
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 'LEFT JOIN requests ON queue.reqID = requests.reqID ORDER by rank ASC' at line 1
I can't seem to figure it out, any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很接近。
WHERE
子句应位于LEFT JOIN
之后。You were close. The
WHERE
clause should go after theLEFT JOIN
.连接是查询的
from
部分的一部分,因此必须位于where
部分之前:The joins are part of the
from
section of a query, and, as such, must come before thewhere
section :