【SQL】Oracle的内连接、左外连接、右外连接及全外连接
来源:互联网 发布:php curl 请求头 编辑:程序博客网 时间:2024/06/05 00:56
理解Oracle的各种连接方法的最有效的方法就是“躬亲”,在实践中去深刻理解内连接,左外连接,右外连接,全外连接的概念的和效果。
1.创建测试表并准备测试数据
sec@ora10g> create table a (a number(1),b number(1),c number(1));
sec@ora10g> create table b (a number(1),d number(1),e number(1));
sec@ora10g> insert into a values(1,1,1);
sec@ora10g> insert into a values(2,2,2);
sec@ora10g> insert into a values(3,3,3);
sec@ora10g> insert into b values(1,4,4);
sec@ora10g> insert into b values(2,5,5);
sec@ora10g> insert into b values(4,6,6);
sec@ora10g> commit;
sec@ora10g> select * from a;
A B C
---------- ---------- ----------
1 1 1
2 2 2
3 3 3
sec@ora10g> select * from b;
A D E
---------- ---------- ----------
1 4 4
2 5 5
4 6 6
2. 内连接
sec@ora10g> select * from a, b where a.a=b.a;
另外一种写法如下
sec@ora10g> select * from a inner join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3.左外连接
sec@ora10g> select * from a,b where a.a=b.a(+);
另外一种写法如下
sec@ora10g> select * from a left outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3 3 3
4.右外连接
sec@ora10g> select * from a,b where a.a(+)=b.a;
另外一种写法如下
sec@ora10g> select * from a right outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
4 6 6
5.全外连接
sec@ora10g> select * from a full outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3 3 3
4 6 6
6.小结
通过使用Oracle提供的各种SQL连接功能可以解决诸多的“疑难杂症”,需灵活掌握。
Good luck.
secooler
10.10.17
-- The End --
1.创建测试表并准备测试数据
sec@ora10g> create table a (a number(1),b number(1),c number(1));
sec@ora10g> create table b (a number(1),d number(1),e number(1));
sec@ora10g> insert into a values(1,1,1);
sec@ora10g> insert into a values(2,2,2);
sec@ora10g> insert into a values(3,3,3);
sec@ora10g> insert into b values(1,4,4);
sec@ora10g> insert into b values(2,5,5);
sec@ora10g> insert into b values(4,6,6);
sec@ora10g> commit;
sec@ora10g> select * from a;
A B C
---------- ---------- ----------
1 1 1
2 2 2
3 3 3
sec@ora10g> select * from b;
A D E
---------- ---------- ----------
1 4 4
2 5 5
4 6 6
2. 内连接
sec@ora10g> select * from a, b where a.a=b.a;
另外一种写法如下
sec@ora10g> select * from a inner join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3.左外连接
sec@ora10g> select * from a,b where a.a=b.a(+);
另外一种写法如下
sec@ora10g> select * from a left outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3 3 3
4.右外连接
sec@ora10g> select * from a,b where a.a(+)=b.a;
另外一种写法如下
sec@ora10g> select * from a right outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
4 6 6
5.全外连接
sec@ora10g> select * from a full outer join b on a.a=b.a;
A B C A D E
---------- ---------- ---------- ---------- ---------- ----------
1 1 1 1 4 4
2 2 2 2 5 5
3 3 3
4 6 6
6.小结
通过使用Oracle提供的各种SQL连接功能可以解决诸多的“疑难杂症”,需灵活掌握。
Good luck.
secooler
10.10.17
-- The End --
0 0
- 【SQL】Oracle的内连接、左外连接、右外连接及全外连接
- Oracle的内连接、左外连接、右外连接及全外连接
- Oracle的内连接、左外连接、右外连接及全外连接
- Oracle的内连接、左外连接、右外连接及全外连接
- Oracle 的四种连接-左外连接、右外连接、内连接、全外连接
- sql的交叉连接,内连接,左外连接,右外连接,全外连接总结
- Oracle 的四种连接-左外连接、右外连接、内连接、全连接
- Oracle 的四种连接-左外连接、右外连接、内连接、全连接
- SQL 左外连接,右外连接,全连接,内连接 4种连接的区别
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- SQL 左外连接,右外连接,全连接,内连接 4种连接的区别
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- SQL 左外连接,右外连接,全连接,内连接 4种连接的区别 .
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- SQL的四种连接-内连接、左外连接、右外连接、全连接
- SQL的四种连接:内连接 左外连接 右外连接 全连接
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- poj 2823 Sliding Window 单调队列
- myeclipse10配置maven
- Android菜鸟在成长-ListView1
- DetectSourceDemo
- uva 439(bfs)
- 【SQL】Oracle的内连接、左外连接、右外连接及全外连接
- 理解Linux系统/etc/init.d目录和/etc/rc.local脚本
- 自定义事件
- [生活]SAE初次体验
- hbase0.96 put流程 源代码分析
- 4.5poj2975Acesar密码
- js高级程序设计第三版 第四章
- 书写优雅的shell脚本(插曲) - kill
- android中tesseract-ocr的介绍