SQL多表查询语句
来源:互联网 发布:js解压缩工具 编辑:程序博客网 时间:2024/05/09 19:09
带【in】的嵌套查询
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal in (select sal from scott.emp where ename='WARD');
上述语句完成的是查询薪水和WARD相等的员工,也可以使用【not in】来进行查询。
带【any】的嵌套查询
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal >any(select sal from scott.emp where job='MANAGER');
带any的查询过程等价于两步的执行过程。
(1)执行“select sal from scott.emp where job='MANAGER'”]
(2)查询到3个薪水值2975、2850和2450,父查询执行下列语句。
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal >2975 or sal>2850 or sal>2450;
带【some】的嵌套查询
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal =some(select sal from scott.emp where job='MANAGER');
带some的嵌套查询与any的步骤相同。
(1)子查询,执行“select sal from scott.emp where job='MANAGER'”
(2)父查询执行下列语句。
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal =2975 or sal=2850 or sal=2450;
带【any】的嵌套查询和【some】的嵌套查询功能是一样的。早期的SQL仅仅允
许使用【any】,后来的版本为了和英语的【any】相区分,引入了【some】,同时还保留了【any】
关键词。
带【all】的嵌套查询
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal >all(select sal from scott.emp where job='MANAGER');
带all的嵌套查询与【some】的步骤相同
select emp.empno,emp.ename,emp.job,emp.sal
from scott.emp
where sal >2975 and sal>2850 and sal>2450;
并操作的嵌套查询
并操作就是集合中并集的概念。属于集合A或集合B的元素总和就是并集。
(select deptno from scott.emp)
union
(select deptno from scott.dept);
交操作的嵌套查询
交操作就是集合中交集的概念。属于集合A且属于集合B的元素总和就是交集
(select deptno from scott.emp)
intersect
(select deptno from scott.dept);
差操作的嵌套查询
差操作就是集合中差集的概念。属于集合A且不属于集合B的元素总和就是差集
(select deptno from scott.dept)
minus
(select deptno from scott.emp);
并、交和差操作的嵌套查询要求属性具有相同的定义,包括类型和取值范围
- SQL多表查询语句
- SQL多表查询语句
- SQL多表查询语句
- SQL语句多表查询
- sql语句多表查询
- SQL语句多表查询
- sql语句多表查询
- SQL语句多表查询
- SQL语句多表查询
- SQL查询语句《三》:多表查询
- 多表查询SQL 语句优化
- 一个多表查询的SQL语句
- 【多表查询】一条sql语句
- 多表联合查询SQL语句
- SQL语句:查询多表更新数据
- sql语句多表查询实例
- SQL 多表连接查询实现语句
- sql多表查询语句的学习
- 动态规划_Dynamic Programming
- 编写数据库应用程序
- MS SQL Server 2000系统数据类型
- 贪吃蛇游戏的源代码(汇编)
- “灰鸽子”木马程序再度重现升级为“黑鸽子”
- SQL多表查询语句
- hibernate增删查改
- 光纤
- (代码实现)北京大学-JudgeOnline-1318
- 设计模式讨论之abstract factory篇
- 设计模式之abstract factory篇(例子)
- 设计模式之abstract factory篇(3)
- extends和implements的区别
- 木马