简体   繁体   English

在我的MySQL中,使用单词JOIN或使用:table1.id = table2.id有什么区别?

[英]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顺序。

From manual : 手册

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.

相关问题 MySQL使用table1.id REGEXP table2.id为同一组选择不同的行 - MySQL select distinct rows for same group using table1.id REGEXP table2.id PHP MYSQL JOIN QUERY 2 数据库,其中 table1.id = table2.id,如何将 table2.content 显示为 table1.id - PHP MYSQL JOIN QUERY 2 Databases, Where table1.id = table2.id, How to display table2.content as table1.id MySQL-如果table1.id = table2.id> 1则显示一行 - Mysql - Show one row if table1.id = table2.id > 1 MySQL Select语句where table1.id!= table2.id - MySQL Select statement Where table1.id != table2.id SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id WHERE子句 - SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id WHERE clause 当我使用此php时,结果显示所有表而不是table1.id = table2.id的特定条件 - When i use this php the results show all the table not the specific condition that table1.id = table2.id 当table1.id = table2.id时如何打印一件事,而如果“ if else”又如何打印? - How can I print one thing when table1.id=table2.id, and another thing 'if else'? 连接两个表,其中table1.id等于table2.table1_id,但仅显示table1.id中在table2.table1_id中找不到的行 - Join two tables where table1.id equals table2.table1_id, but only display rows from table1.id that cannot be found in table2.table1_id MySQL 如果 table1.id = table2.table1_id 查询应该在第一个表中插入第二个表 - MySQL Query should insert a second table into the first table if table1.id = table2.table1_id Mysql - UPDATE表SET列= SELECT COUNT(*)FROM(SELECT * FROM table2 WHERE table2.id = table.id))不可能 - Mysql — UPDATE table SET column = SELECT COUNT(*) FROM ( SELECT * FROM table2 WHERE table2.id = table.id ) ) Impossible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM