SQL中JOIN的使用
(注:outer的意思就是"没有关联上的行"。)
1.cross join 全外连接(笛卡尔乘积)
SELECT A.*, B.* from A FULL OUTER JOIN B ON A.ID = B.ID
2.inner join 内连接(在笛卡尔乘积的结果集中去掉不符合连接条件的行)
SELECT A.* from A INNER JOIN B ON A.ID=B.ID
3.left outer join 左外连接(在inner join的结果集上加上左表中没被选上的行,行的右表部分每个字段都用NUll填充)
SELECT A.* from A LEFT JOIN B ON A.ID = B.ID
4.right outer join 右外连接(在inner join的结果集上加上右表中没被选上的行,行的左表部分全用NULL填充。)
SELECT A.* from A RIGHT JOIN B ON A.ID = B.ID
举例说明:
表A
记录如下:
aID aNum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
表B
记录如下:
bID bName
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
实验如下
:
1.left join
sql
语
相关文档:
第二十题:
怎么样抽取重复记录
表:
id name
--------
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
2 test2
3 test3
2 test2
6 test6
查出所有有重复记录的数据,用一句sql 来实现
create table D(
id varchar (20),
name varchar (20)
)
insert into D values('1','test1')
insert into D v ......
constraint Example:
1. grammer:
create table [schema.]table
(column datatype [DEFAULT expr]
[column_constraint], ...
[table_constraint] [,......]);
2. example of a column_level constraint:
create table empl ......
Confirming granted privileges
Data Dictionary View Description
ROLE_SYS_PRIVS System privileges granted to roles
ROLE_TAB_PRIVS & ......
在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钓的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据 ......