在阅读英文资料时候,经常会读到join类型的英文单词,以下是总结join 类型的含义:
1、cross joins,也叫做cartestian product,意思是将表A的每一行与表B的所有行组和起来,语句如下:
SQL>select * from tab1, tab2
或
SQL>select * from tab1 cross join b
2、Theta Joins : 从cross join的结果集中挑选出符合关联条件的行,类似如下:
SQL> select * from tab1, tab2
where tab1.col1 between tab2.col1 between tab2.col2
或
SQL>select * from tab1, tab2
where tab1 join tab2 on tab1.col1 between tab2.col1 between tab2.col2
或
SQL>select * from tab1, tab2
where tab1 inner join tab2
on tab1.col1 between tab2.col1 between tab2.col2
3、Equi-Joins:是Theta join的特殊类型,关联条件是“=”,如:
SQL>select * from tab1, tab2
where tab1.col1=tab2.col2
或
SQL>select * from tab1, tab2
where tab1 join tab2 on tab1.col1=tab2.col1
4、self-join: 是Theta关联的特殊类型,表自己关联自己
SQL>select * from tab1, tab1 tab2
where tab1.col1=tab2.col2
或
SQL>select * from tab1, tab1 tab2
where tab1 join tab1 tab2 on tab1.col1 = tab1.col2
5、outer-joins: 是theta joins结果集的扩展,显示一个表的所有结果集,即使该表关联条件值与另一个表不匹配。
SQL>select * from tab1, tab2
where tab1.col1=tab2.col1(+)
或
SQL>select * from tab1, tab2
where tab1 left join tab2 on tab1.col1=tab2.col1
或
SQL>select * from tab1, tab2
where tab1 left outer join tab2 on tab1.col1=tab2.col1
6、semi-joins: 一张表匹配另一个表的行,通常被写成IN或EXISTS
SQL>select * from tab1
where tab1.col1 in (select col1 from tab2)
SQL>select * from tab1
where exists (select * from tab2 where tab1.col1=tab2.col1)
7、Anti-Joins: 返回一张表不匹配另一张表的行,通常是写成NOT IN或NOT EXISTS
SQL>select * from tab1
where tab1.col1not in (select col1 from tab2)
SQL>select * from tab1
where not exists (select * from tab2 where tab1.col1=tab2.col1)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/354732/viewspace-619381/
,如需转载,请注明出处,否则将追究法律责任。