ORACLE连接 (+)和Join总
2016-04-25 22:26
525 查看
一.笛卡尔积
a.oracle写法scott@ORCL> select count(1) from emp;
COUNT(1)
----------
14
scott@ORCL> select count(1) from dept;
COUNT(1)
----------
4
scott@ORCL> select count(1) from emp,dept;
COUNT(1)
----------
56
b.传统sql写法
scott@ORCL> select count(1) from emp cross join dept;
COUNT(1)
----------
56
二.等值连接(也叫作内连接)
a.oracle写法scott@ORCL> select count(1) from emp a,dept b where a.deptno=b.deptno;
COUNT(1)
----------
14
b.传统sql写法
scott@ORCL> select * from emp a join dept b on a.deptno=b.deptno;
else1:等值连接的记录筛选
a.
scott@ORCL> select * from emp a,dept b where a.deptno=b.deptno and a.deptno=30;
b.
scott@ORCL> select * from emp a join dept b on a.deptno=b.deptno where a.deptno=30;
else2:不等值连接
a.
scott@ORCL> select * from emp a,salgrade b where a.sal>=b.losal and a.sal<=b.hisal;
b.
scott@ORCL> select * from emp a join salgrade b on a.sal between b.losal and b.hisal;
三.外连接
1.左外连接(left outer join)a.
scott@ORCL> select * from emp a,dept b where a.deptno=b.deptno(+);
b.
scott@ORCL> select * from emp a left outer join dept b on a.deptno=b.deptno;
2.右外连接
a.
scott@ORCL> select * from emp a,dept b where a.deptno(+)=b.deptno;
b.
scott@ORCL> select * from emp a right outer join dept b on a.deptno=b.deptno;
3.全外连接
a.
scott@ORCL> select * from emp a,dept b where a.deptno(+)=b.deptno union
2 select * from emp a,dept b where a.deptno=b.deptno(+);
b.
scott@ORCL> select * from emp a full outer join dept b on a.deptno=b.deptno;
四.自然连接:根据两个表的相同字段
scott@ORCL> select * from emp natural join dept b;如果两张表没有相同字段会报错:没有选定行
五.using字句:指定表的某个字段作为连接的字段
scott@ORCL> select * from emp a join dept b using(deptno);相关文章推荐
- oracle登录
- oracle用户权限、角色管理详解
- 官网 Mysql Installing MySQL on Linux Using RPM Packages from Oracle
- oracle数据库导入导出cmd命令
- oracle 常用命令
- Linux 平台静默安装 Oracle客户端
- Oracle--单行函数
- Oracle中insert into select和select into的用法(异常0RA-00905:missing keyword的解决)
- Oracle--sqlplus常用命令,持续更新...
- 《oracle每日一练》Oracle DBLink连接数过多的问题(Ora-02020)
- mysql相似于oracle的to_char() to_date()方法
- Oracle用定时任务存储过程将数据转存到历史表,提高查询速度
- Oracle 11g笔记——自动存储管理(ASM)
- Oracle 11g笔记——调整表空间和数据文件的大小、移动数据文件、联机重做日志文件、控制文件
- 坑爹的oracle11g新特性 密码延迟验证
- oracle imp-000008错误的解决办法
- Oracle 复合索引
- oracle的正则表达式 [转载]
- Oracle-BPM(六)
- Oracle-BPM(五)