Home > Database > Mysql Tutorial > body text

Oracle中的Exists、In、ANY、ALL

WBOY
Release: 2016-06-07 15:19:46
Original
1328 people have browsed it

Exists:子查询至少返回一行时条件为true。 Not Exists:子查询不返回任何一行时条件为true。 In:与子查询返回结果集中某个相等。 Not In:与子查询返回结果集中任何一个不相等。 ANY:比子查询返回结果中的某个大。 =ANY:与子查询返回结果中的某个相等。

Exists:子查询至少返回一行时条件为true。

Not Exists:子查询不返回任何一行时条件为true。

In:与子查询返回结果集中某个值相等。

Not In:与子查询返回结果集中任何一个值不相等。

>ANY:比子查询返回结果中的某个值大。

=ANY:与子查询返回结果中的某个值相等。

>ALL:比子查询返回结果中的所有值都大。

1、查询与10号部门某个员工工资相等的员工信息。

select empno ,ename,sal from emp 
where sal in(select sal from emp where deptno=10)
Copy after login

下面这句话与上的语句效果一样

select empno ,ename,sal from emp 
where sal=any(select sal from emp where deptno=10)
Copy after login

效果如下图:

Oracle中的Exists、In、ANY、ALL

小注:

        =any()括号中即使出现重复的值,也不会报错,比如:

select empno ,ename,sal from emp 
where sal=any(2450.00,5000.00,5000.00)
Copy after login
2、查询比10号部门某个员工工资高的员工信息。
select empno ,ename,sal from emp 
where sal >any(select sal from emp where deptno=10)
Copy after login

在emp表中工资的最小值为1300,下面这句话与上面语句的效果一样

select empno ,ename,sal from emp 
where sal >1300
Copy after login

效果如下图:

Oracle中的Exists、In、ANY、ALL

3、查询比10号部门所有员工工资高的员工信息。

select empno ,ename,sal from emp 
where sal >all(select sal from emp where deptno=10)
Copy after login

效果如下图(没有查询到数据):

Oracle中的Exists、In、ANY、ALL


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!