交叉联结
结果集的行:将第一个表的行数乘以第二表的行数 等于 将产生的结果集的总行数;这个结果集称为笛卡尔结果集;
结果集的列:在第一个表和第二个表中,将SELECT
选择的列合并成一行,注意:选择的列不能同时存在于两个表中;
示例如下:
COMPANY表
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
DEPARTMENT表
ID DEPT EMP_ID
---------- ---------- ----------
1 IT Billing 1
2 Engineerin 2
3 Finance 7
语句:
SELECT NAME, DEPT, EMP_ID FROM DEPARTMENT CROSS JOIN COMPANY
结果集如下:
EMP_ID NAME DEPT
---------- ---------- ----------
1 Paul IT Billing
2 Paul Engineerin
7 Paul Finance
1 Allen IT Billing
2 Allen Engineerin
7 Allen Finance
1 Teddy IT Billing
2 Teddy Engineerin
7 Teddy Finance
1 Mark IT Billing
2 Mark Engineerin
7 Mark Finance
1 David IT Billing
2 David Engineerin
7 David Finance
1 Kim IT Billing
2 Kim Engineerin
7 Kim Finance
1 James IT Billing
2 James Engineerin
7 James Finance
对于上面的查询语句,不能选择同时存在于COMPANY和DEPARTMENT中的列,如选择ID,否则会报错
网友评论