从表1,表2中选择 [英] Select from Table1, Table2

查看:58
本文介绍了从表1,表2中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了以下查询,如果有人可以帮助我向我解释这是什么意思,我将不胜感激.

I found the following query and appreciate it if someone can help explain to me what this means.

select * from table1, table2

推荐答案

这称为CROSS JOIN,但在FROM子句中使用带有,的旧语法.我的建议是不要使用旧的语法,请在此处使用JOIN.

This is called CROSS JOIN but using old syntax with , in FROM clause. My advice is not to use old syntax, stick with the JOIN here.

它产生笛卡尔积,因此结果集中的行数将是table1中的行数乘以table2中的行数(假设WHERE子句中没有约束) .它有效地将table1中的每一行与table2中的一行配对.

It produces a cartesian product, so the number of rows in the result set will be the number of rows from table1 multiplied by number of rows from table2 (assuming there are no constraints in the WHERE clause). It effectively pairs each row from table1 with a row coming from table2.

以下查询是等效的,但会执行显式的JOIN操作,该操作将数据检索的约束逻辑(通常放在WHERE子句中)与连接存储在单独表中(在FROM子句中)的相关数据的逻辑分开:

Below query is an equivalent but does explicit JOIN operation which separates constraint logic of data retrieval (normally put within the WHERE clause) from logic of connecting related data stored across separate tables (within the FROM clause):

SELECT *
FROM table1
CROSS JOIN table2

考虑一个示例,其中table1具有8行,而table2具有5行.在输出中,您将获得40行(8行* 5行),因为它将来自两个源(表)的所有行配对.

Consider an example where table1 has 8 rows and table2 has 5 rows. In the output, you get 40 rows (8 rows * 5 rows), because it pairs all rows from both sources (tables).

这篇关于从表1,表2中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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