oracle中的左右连接
来源:互联网 发布:linux时间设置 编辑:程序博客网 时间:2024/05/11 04:31
在oracle中左右连接省去了sql server中复杂的连接语句(left join ,right join),就用一个"(+)"表示。
下面做了下实验:其中查询1和查询2是等同效果的,查询3和查询4是等同效果的。
查询1:
select first_name,department_name,emp.department_id from emp,departments dept
where emp.department_id(+)=dept.department_id;
122 rows selected.
查询2:
select first_name,department_name,emp.department_id from departments dept left join emp
on emp.department_id=dept.department_id;
122 rows selected.
查询3:
select first_name,department_name,emp.department_id from emp,departments dept
where emp.department_id=dept.department_id(+);
107 rows selected.
查询4:
select first_name,department_name,emp.department_id from emp left join departments dept
on emp.department_id=dept.department_id;
107 rows selected.
总结:
1,(+)在哪一边,则返回另一边所有的记录。
2,(+)放在包含空值的一边,不可以两边同时使用。
补充内联的写法即用using关键词:
select first_name,department_name,department_id from emp join departments dept using(department_id);
注意:USING里的字段不能带别名,SELECT_LIST里的USING里的字段也不能带别名,看下面的两个例子:
select first_name,department_name,emp.department_id from emp join departments dept using(emp.department_id);
using(emp.department_id)
*
ERROR at line 2:
ORA-01748: only simple column names allowed here
select first_name,department_name,emp.department_id from emp join departments dept using(department_id);
select first_name,department_name,emp.department_id from emp join departments dept
*
ERROR at line 1:
ORA-25154: column part of USING clause cannot have qualifier
join using他相当于inner join
select emp.first_name,dept.department_name,emp.department_id from emp join departments dept
on emp.department_id=dept.department_id;
- oracle中的左右连接
- oracle中的左右连接
- oracle中的左右连接
- oracle中的左右外连接
- oracle中的左右外连接
- oracle 左右连接
- oracle左右连接
- oracle左右连接总结
- oracle左右连接相关
- oracle连接 左右
- oracle左右连接
- Oracle左右连接
- oracle左右连接
- ORACLE左右连接
- oracle左右连接
- oracle左右连接
- oracle左右全连接
- oracle ----左右连接
- hm 10.0的运行过程
- ZOJ1005
- service bound(二)
- 新型流感,注意防护,防护措施:
- linux的路径中./.是什么意思 比如说搜索某个文件,发现该文件在./.mozilla/a/b/c/该文件
- oracle中的左右连接
- 使用预定义模型 QStringListModel例子
- php 升级后 htmlspecialchars 返回空 的解决方案
- 学习C++:实践者的方法(Beta1)
- Window7訪問Linux Samba共享文件問題解決。
- php动态页生成静态页的实用方法
- 130331周赛
- Ext.data-Store用法
- 深入理解计算机系统第六章--存储器层次结构与性能