如何从两个表之间用逗号分隔的SELECT工作? (SELECT * FROM T1,T2) [英] How does SELECT from two tables separated by a comma work? (SELECT * FROM T1, T2)

查看:1243
本文介绍了如何从两个表之间用逗号分隔的SELECT工作? (SELECT * FROM T1,T2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定2个表T1和T2。

Given 2 tables T1 and T2.

T1   T2 
---------
A    1 
B    2
C    3

SELECT * 
  FROM T1, T2

从此查询中提取的行的no是什么?

What is the no: of rows that are fetched from this query?

(a) 4
(b) 5
(c) 6
(d) 9



答案是:9



问题:



为什么答案是9?

Answer is : 9

Question:

Why is the answer "9"?

推荐答案

两个表格之间的逗号表示 CROSS JOIN , a href =http://en.wikipedia.org/wiki/Cartesian_product =noreferrer>笛卡尔积。您的查询等效于:

The comma between the two tables signifies a CROSS JOIN, which gives the Cartesian product of the two tables. Your query is equivalent to:

SELECT *
FROM T1
CROSS JOIN T2

结果是第一个表中的一行与第二个表中的一行的每个配对。因此,结果中的行数是原始表中行数的乘积。在这种情况下,答案是3 x 3 = 9。

The result is every pairing of a row from the first table with a row from the second table. The number of rows in the result is therefore the product of the number of rows in the original tables. In this case the answer is 3 x 3 = 9.

行将如下所示:

T1.foo   T2.bar
A        1
A        2
A        3
B        1
B        2
B        3
C        1
C        2
C        3

这篇关于如何从两个表之间用逗号分隔的SELECT工作? (SELECT * FROM T1,T2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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