php中mysql的左连接/外键问题

发布于 2024-11-28 05:53:57 字数 600 浏览 0 评论 0原文

我有表队列和请求。队列的 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 技术交流群。

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

发布评论

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

评论(2

菩提树下叶撕阳。 2024-12-05 05:53:57
$sql = mysql_query("SELECT queue.*, requests.* FROM queue LEFT JOIN requests ON queue.reqID = requests.reqID WHERE queue.vanID = '$vanID' ORDER by rank ASC") or die(mysql_error());

你很接近。 WHERE 子句应位于 LEFT JOIN 之后。

$sql = mysql_query("SELECT queue.*, requests.* FROM queue LEFT JOIN requests ON queue.reqID = requests.reqID WHERE queue.vanID = '$vanID' ORDER by rank ASC") or die(mysql_error());

You were close. The WHERE clause should go after the LEFT JOIN.

最笨的告白 2024-12-05 05:53:57

连接是查询的 from 部分的一部分,因此必须位于 where 部分之前:

SELECT queue.*, requests.* 
FROM queue 
    LEFT JOIN requests ON queue.reqID = requests.reqID 
WHERE queue.vanID = '$vanID' 
ORDER by rank ASC

The joins are part of the from section of a query, and, as such, must come before the where section :

SELECT queue.*, requests.* 
FROM queue 
    LEFT JOIN requests ON queue.reqID = requests.reqID 
WHERE queue.vanID = '$vanID' 
ORDER by rank ASC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文