首页 > 代码库 > SQL中的Filter, join, semi-join等概念的释义

SQL中的Filter, join, semi-join等概念的释义

经常在工作中用到,虽然当年在数据库原理课程中学习过,不过基本已经还给老师了。工作这么多年,感觉自己在学习上倒退了很多,惭愧。这篇帖子,作为SQL相关知识的整理贴。

 

1、semi-join(半连接)(来自:http://wiki.answers.com/Q/What_is_semi_join_in_SQL)

半连接返回表中能够与另一表中连接的记录(并不执行一次全连接),它并没有一个明确的语法格式。

A semi-join returns rows from one table that would join with another table without performing a complete join. It doesn‘t have explicit syntax. 

例子,从表Customers中选择其ID出现在表Sales中的客户的ID和Name:
select * 
from Customers C 
where exists ( 
select * 
from Sales S 
where S.Cust_Id = C.Cust_Id 


Cust_Id Cust_Name 
----------- ---------- 
2 John Doe 
3 Jane Doe

来看看这篇文章:http://blog.csdn.net/tiwen818/article/details/7103711,比较详细的介绍了Oracle中的半连接。惭愧啊,话说这个帖子里面的这个语句我就没看懂:

create table table_1
as select
cast(rownum as int) a,
cast(rownum+10 as int) b,
cast(dbms_random.string(‘i‘,10) as varchar2(10)) c
from dual connect by level<=500000

看了这篇文章http://yesican.blog.51cto.com/700694/269814和这篇http://www.360doc.com/content/13/0422/16/11947209_280153192.shtml才明白。

 

2、join(连接)(来自:http://www.w3schools.com/sql/sql_join.asp)

总共有四种连接类型:

内连接:http://www.w3schools.com/sql/sql_join_inner.asp

全连接:http://www.w3schools.com/sql/sql_join_full.asp

左连接:http://www.w3schools.com/sql/sql_join_left.asp

右连接:http://www.w3schools.com/sql/sql_join_right.asp

 

3、aggregation(聚合)(来自:http://msdn.microsoft.com/zh-cn/library/ms173454.aspx)

聚合函数对一组值执行计算,并返回单个值。 除了 COUNT 以外,聚合函数都会忽略空值。 聚合函数经常与 SELECT 语句的 GROUP BY 子句一起使用。