Oracle86和92语法的连接,子查询,集合的操作
来源:互联网 发布:linux mtd源代码分析 编辑:程序博客网 时间:2024/06/03 10:10
一 比较86和92语法中多表连接区别
1笛卡尔积
--oracle连接的基础 笛卡尔积
--92语法 更加清晰明了的区别了 每一种连接
--解决了多表关联时 条件不清晰的问题
select * from emp;
select * from dept;
--86语法
select * from emp e,dept d;
--92语法
select * from emp cross join dept
2内连接
select * from emp;
select * from dept;
--86语法
select * from emp e,dept d where e.deptno=d.deptno;
--92语法
select * from emp inner join dept on emp.deptno=dept.deptno
3左外连(左外连接和右外联的区别在于 谁为主 谁为从 意义相同)
--86语法
select * from emp e,dept d where e.deptno=d.deptno(+)
--92语法
select * from emp e left join dept d on e.deptno=d.deptno
-- oracle中子查询
表子查询 只要输出的结果是个表结构 就可以放在from后查询 也可以设置别名
select abc.ename,abc.loc from (
select * from emp e inner join dept d on e.deptno=d.deptno
) abc;
select * from emp;
select * from dept;
/**
列的子查询 子查询 永远只能返回一行一列数据
列子查询的原理
for(emp e: list<emp>){
syso(e.ename);
for(dept d: list<dept>){
if(e.deptno==d.deptno){
syso(d.dname)
break;
}
}
}
**/
select ename,(select dname from dept where deptno=e.deptno) from emp e;
--条件子查询
select * from tab;
select * from salgrade
--薪水等级是2的人
select losal,hisal from salgrade where grade=2
select * from emp where sal>=(select losal from salgrade where grade=2)
and sal<=(select hisal from salgrade where grade=2)
select * from emp e inner join salgrade s on e.sal>=s.losal and e.sal<=s.hisal
where s.grade=2
/**
/**
--多行子查询
for(emp e: list<emp>){
syso(e.ename);
for(dept d: list<dept>){
if(d.dname.indexOf('A')>=0){
if(e.deptno==d.deptno ){
syso(d.dname)
break;
}
}
}
}
**/
select * from emp where deptno =any(
select deptno from dept where dname like '%A%'
)
select * from emp where deptno in(
select deptno from dept where dname like '%A%'
)
--效率最高的子查询语句
select * from emp e where exists(
select deptno from dept d where d.deptno=e.deptno and dname like '%A%'
)
2 集合操作符
并集
union all 集合中的元素 全部叠加 不会去重复
union 集合中的元素 全部叠加 会去重复
intersect 交集
{1,2},{2,3} 结果为 {2}
minus 取差集
1笛卡尔积
--oracle连接的基础 笛卡尔积
--92语法 更加清晰明了的区别了 每一种连接
--解决了多表关联时 条件不清晰的问题
select * from emp;
select * from dept;
--86语法
select * from emp e,dept d;
--92语法
select * from emp cross join dept
2内连接
select * from emp;
select * from dept;
--86语法
select * from emp e,dept d where e.deptno=d.deptno;
--92语法
select * from emp inner join dept on emp.deptno=dept.deptno
3左外连(左外连接和右外联的区别在于 谁为主 谁为从 意义相同)
--86语法
select * from emp e,dept d where e.deptno=d.deptno(+)
--92语法
select * from emp e left join dept d on e.deptno=d.deptno
-- oracle中子查询
表子查询 只要输出的结果是个表结构 就可以放在from后查询 也可以设置别名
select abc.ename,abc.loc from (
select * from emp e inner join dept d on e.deptno=d.deptno
) abc;
select * from emp;
select * from dept;
/**
列的子查询 子查询 永远只能返回一行一列数据
列子查询的原理
for(emp e: list<emp>){
syso(e.ename);
for(dept d: list<dept>){
if(e.deptno==d.deptno){
syso(d.dname)
break;
}
}
}
**/
select ename,(select dname from dept where deptno=e.deptno) from emp e;
--条件子查询
select * from tab;
select * from salgrade
--薪水等级是2的人
select losal,hisal from salgrade where grade=2
select * from emp where sal>=(select losal from salgrade where grade=2)
and sal<=(select hisal from salgrade where grade=2)
select * from emp e inner join salgrade s on e.sal>=s.losal and e.sal<=s.hisal
where s.grade=2
/**
/**
--多行子查询
for(emp e: list<emp>){
syso(e.ename);
for(dept d: list<dept>){
if(d.dname.indexOf('A')>=0){
if(e.deptno==d.deptno ){
syso(d.dname)
break;
}
}
}
}
**/
select * from emp where deptno =any(
select deptno from dept where dname like '%A%'
)
select * from emp where deptno in(
select deptno from dept where dname like '%A%'
)
--效率最高的子查询语句
select * from emp e where exists(
select deptno from dept d where d.deptno=e.deptno and dname like '%A%'
)
2 集合操作符
并集
union all 集合中的元素 全部叠加 不会去重复
union 集合中的元素 全部叠加 会去重复
intersect 交集
{1,2},{2,3} 结果为 {2}
minus 取差集
{1,2},{2,3} 结果为{1}
0 0
- Oracle86和92语法的连接,子查询,集合的操作
- Oracle的子查询和集合运算
- MySQL的子查询和连接知识
- 连接查询和子查询的区别(待)
- 数据的增删改查:单表查询,多表查询,集合查询和子查询
- sql的子连接查询
- Oracle基本查询语法-多表查询和子查询和集合运算
- Oracle基本语法&&函数&&子查询&&分页查询&&排序&&集合操作&&高级分组函数
- Oracle基本语法&&函数&&子查询&&分页查询&&排序&&集合操作&&高级分组函数
- SQL(五)查询(三)连接查询、集合操作、嵌套子查询
- MySQL的子查询与连接查询
- MySQL的连接查询及子查询
- 数据库表的连接查询、子查询
- 基于连接和子查询的update语句
- Mysql 的连接(join)和子查询
- Oracle 学习笔记 14 -- 集合操作和高级子查询
- List集合的动态查询Func语法
- 子查询和连接
- java学习中一些基础知识(二)
- AndroidStudio 报错 finished with non-zero exit value 2
- 使用Ant定义生成文件
- Android之手机通知栏Notification介绍(一)
- Github优秀开源项目(注意!!里面有 巨图 和 大型gif图)
- Oracle86和92语法的连接,子查询,集合的操作
- 笔试题82.新浪微博算法题
- TYVJ 1864 BZOJ 3029 守卫者的挑战
- Import Error: No module name libstdcxx
- Spring学习(一)—入门
- 额,先这样
- Ant生成文件结构
- 个人小 demo
- Volley网络请求框架简析——Android网络请求框架(三)