如何在没有ON条件的情况下使用mysql JOIN? [英] How to use mysql JOIN without ON condition?

查看:1181
本文介绍了如何在没有ON条件的情况下使用mysql JOIN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有ON语句的情况下编写联接查询?以及这些联接的不同之处LEFT JOIN, RIGHT JOIN的工作原理.

Is it possible to write join query without ON statement? and how do these joins differ LEFT JOIN, RIGHT JOIN works.

推荐答案

MySQL 文档涵盖了这个主题.

MySQL documentation covers this topic.

这里是提要.使用joininner join时,on条件是可选的.这与ANSI标准不同,并且与几乎所有其他数据库不同.效果是cross join.同样,您可以在cross join中使用on子句,该子句也与标准SQL不同.

Here is a synopsis. When using join or inner join, the on condition is optional. This is different from the ANSI standard and different from almost any other database. The effect is a cross join. Similarly, you can use an on clause with cross join, which also differs from standard SQL.

交叉连接将创建笛卡尔乘积-即,第一个表中的第一行和第二个表中的第一行的每种可能组合.具有三行('a','b'和'c')的表和具有四行(例如1、2、3、4)的表的交叉联接将具有12行.

A cross join creates a Cartesian product -- that is, every possible combination of 1 row from the first table and 1 row from the second. The cross join for a table with three rows ('a', 'b', and 'c') and a table with four rows (say 1, 2, 3, 4) would have 12 rows.

在实践中,如果要进行交叉联接,请使用cross join:

In practice, if you want to do a cross join, then use cross join:

from A cross join B

比:

from A, B

和:

from A join B -- with no on clause

on子句是左右外部联接所必需的,因此讨论与它们无关.

The on clause is required for a right or left outer join, so the discussion is not relevant for them.

如果您需要了解联接的不同类型,则需要对关系数据库进行一些研究.在该级别的讨论中,Stackoverflow不合适.

If you need to understand the different types of joins, then you need to do some studying on relational databases. Stackoverflow is not an appropriate place for that level of discussion.

这篇关于如何在没有ON条件的情况下使用mysql JOIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆