[英]In my MySQL what is the difference between using the word JOIN or using: table1.id=table2.id
In my MySQL what is the difference between using the word JOIN or using: table1.id=table2.id 在我的MySQL中,使用单词JOIN或使用:table1.id = table2.id有什么区别?
Table 1
id name
1 John Lennon
Table 2
id position
1 Singer
//What is the difference then calling JOIN? //然后调用JOIN有什么区别?
Select name, position
From Table1, Table2
Where Table1.id=Table2.id;
If this case, there's no difference. 如果是这种情况,就没有区别。 But the joins can also be: INNER, OUTER (left outer, right outer, full outer joins), LEFT, RIGHT.
但是联接也可以是:INNER,OUTER(左外部,右外部,全外部联接),LEFT,RIGHT。
There is none as long as there are only two tables. 只要有两个表就没有。 When there are more, you might get different JOIN order than expected, if you use comma to separate tables.
如果还有更多,如果使用逗号分隔表,则可能会获得与预期不同的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和,(逗号)在语义上等效:在指定的表之间都产生笛卡尔积(即,第一个表中的每一行都与第二个表中的每一行都联接在一起) )。
However, the precedence of the comma operator is less than of INNER JOIN, CROSS JOIN, LEFT JOIN, and so on.
但是,逗号运算符的优先级小于INNER JOIN,CROSS JOIN,LEFT JOIN等。 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.
如果在存在联接条件时将逗号联接与其他联接类型混合使用,则可能会出现“ on子句”中形式为“未知列” col_name”的错误。 Information about dealing with this problem is given later in this section.
本节稍后将提供有关解决此问题的信息。
Using a JOIN
is known as an "explicit join", or an ANSI join... separating your tables with a comma and then linking them in the WHERE
clause is known as an "implicit join". 使用
JOIN
被称为“显式连接”或ANSI连接...用逗号分隔表,然后在WHERE
子句中链接它们被称为“隐式连接”。
The ANSI join is widely considered to be the preferred syntax. ANSI连接被广泛认为是首选语法。 It is easier to follow, less ambiguous, and more consistent when you need to start adding outer joins.
当您需要开始添加外部联接时,它更容易遵循,更清晰,更一致。
Additionally, if you use the implicit join syntax, it is easy to end up with an accidental cross join if you forget to link the tables in your WHERE
clause. 此外,如果使用隐式联接语法,如果您忘记在
WHERE
子句中链接表,则很容易以意外的交叉联接结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.