且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL LEFT JOIN错误

更新时间:2022-06-08 21:27:56

您需要使用INNER JOIN而不是逗号运算符来重写查询:

You need to rewrite the query using INNER JOIN instead of comma operator:

SELECT portfolio.*, projects.*, types.*
FROM projects
INNER JOIN types
ON projects.projectType = types.typeID
LEFT JOIN portfolio
ON portfolio.pfProjectID = projects.projectID
WHERE types.typeID = #URL.a#
ORDER BY types.typeSort, projects.projectPriority ASC

说明:

这与MySQL更改运算符优先级以符合ANSI标准有关.查看MySQL文档: http://dev.mysql.com/doc/refman/5.1/en/join.html

This has to do with MySQL changing operator precedence to comply with ANSI standards. Check out the MySQL documentation: http://dev.mysql.com/doc/refman/5.1/en/join.html

INNER JOIN和,(逗号)是 在没有语义上是等价的 联接条件:都产生一个 之间的笛卡尔积 指定的表格(即每个 第一个表中的每一行都被连接 到第二行中的每一行 表格).

INNER JOIN and , (comma) are semantically equivalent in the absence of a join condition: both produce a Cartesian product between the specified tables (that is, each and every row in the first table is joined to each and every row in the second table).

但是,逗号的优先级 运算符小于INNER JOIN, 交叉联接,左联接等.如果 您将逗号连接与另一个 有联接时的联接类型 条件,形式错误 开"中的未知列"col_name" 子句"可能会发生.相关信息 给出了解决这个问题的方法 在本节的后面.

However, the precedence of the comma operator is less than of INNER JOIN, CROSS JOIN, LEFT JOIN, and so on. If you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur. Information about dealing with this problem is given later in this section.

MySQL页面上还有更详细的说明,搜索以前是逗号运算符(,)"

There is also more detailed explanation on MySQL page, search for "Previously, the comma operator (,)"