`
二当家的
  • 浏览: 23586 次
文章分类
社区版块
存档分类
最新评论

sql里in,all,any,some的区别和具体应用范围

 
阅读更多
in 是 确定集合的

SELECT au_lname, state
FROM authors
WHERE state IN ('CA', 'IN', 'MD')
结果:
au_lname   state
--------   ----
Yokomoto      CA
DeFrance      IN
Stringer      CA
MacFeather    CA
Karsen        CA
Panteley      MD
Hunter        CA

all 是查询还可以是子查询
如:

select name from edit
其中name前省略了all.
name前可以加ALL|DISTINCT
all是所有记录.
distinct是不重复的。

带【any】的嵌套查询和【some】的嵌套查询功能是一样的。早期的SQL仅仅允许使用【any】,后来的版本为了和英语的【any】相区分,引入了【some】,同时还保留了【any】关键词。
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'”
 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'”,其结果如图4.22所示。
    (2)父查询执行下列语句。
    ――――――――――――――――――――――――――――――――――――― 
    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =2975 or sal=2850 or sal=2450;
分享到:
评论

相关推荐

    sql中all,any,some用法

    sql中all,any,some用法实现语句,需要的朋友可以看下。

    SQL Server 2016 Developer's Guide

    All the concepts are explained in a very easy-to-understand manner and are supplemented with examples to ensure that you—the developer—are able to take that next step in building more powerful, ...

    sql 2005 new feature

    that you have some familiarity with SQL Server 2000, but you should be able to follow along even if you are new to SQL Server 2005. For many topics I tell you where I describe the functionality in ...

    程序员的SQL金典.rar

     8.4.2 ANY和SOME运算符  8.4.3 ALL运算符  8.4.4 EXISTS运算符  8.5 在其他类型SQL语句中的子查询应用  8.5.1 子查询在INSERT语句中的应用  8.5.2 子查询在UPDATE语句中的应用  8.5.3 子查询在DELETE语句中...

    The Art of SQL

    You can hardly interview a young developer today who doesn't claim a good working knowledge of SQL, the lingua franca of database access, a standard part of any basic IT course. This claim is usually ...

    Begining SQL

    SQL is an international standard for manipulating data in databases and is used by database programmers in all major database systems: Microsoft, IBM, Oracle, MySQL, and many others From the Back ...

    程序员的SQL金典4-8

     8.4.2 ANY和SOME运算符  8.4.3 ALL运算符  8.4.4 EXISTS运算符  8.5 在其他类型SQL语句中的子查询应用  8.5.1 子查询在INSERT语句中的应用  8.5.2 子查询在UPDATE语句中的应用  8.5.3 子查询在DELETE语句中...

    Oracle PL/SQL Best Practices

    You will undoubtedly find recommendations in this book that also appear in some of my other books; I hope you will not be offended by this repetition. It's simply impossible to offer in a single book ...

    微软内部资料-SQL性能优化5

    In SQL Server 2000, all clustered indexes are unique. If you build a clustered index without specifying the unique keyword, SQL Server forces uniqueness by adding a uniqueifier to the rows when ...

    微软内部资料-SQL性能优化2

    In this module we will discuss Microsoft® SQL Server™ interaction with the operating system and methodology of troubleshooting server-based problems. At the end of this module, you will be able to:...

    微软内部资料-SQL性能优化3

    An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...

    SQL Prompt_9.1.12.5083破解版

    SP-6939 : Code analysis no longer reports non-scalar false positives on subqueries surrounded by ANY, ALL and SOME logical operators (EI003). SP-6957 : SELECT NULL produces a scalar value, so it ...

    SQL Prompt_9.1.14.5213破解版

    SP-6939 : Code analysis no longer flags an EI003 if a non-scalar subquery is contained within a scalar function, such as ANY, ALL or SOME. See the full release notes for more information.

    程序员的SQL金典6-8

     8.4.2 ANY和SOME运算符  8.4.3 ALL运算符  8.4.4 EXISTS运算符  8.5 在其他类型SQL语句中的子查询应用  8.5.1 子查询在INSERT语句中的应用  8.5.2 子查询在UPDATE语句中的应用  8.5.3 子查询在DELETE语句中...

    程序员的SQL金典7-8

     8.4.2 ANY和SOME运算符  8.4.3 ALL运算符  8.4.4 EXISTS运算符  8.5 在其他类型SQL语句中的子查询应用  8.5.1 子查询在INSERT语句中的应用  8.5.2 子查询在UPDATE语句中的应用  8.5.3 子查询在DELETE语句中...

    程序员的SQL金典3-8

     8.4.2 ANY和SOME运算符  8.4.3 ALL运算符  8.4.4 EXISTS运算符  8.5 在其他类型SQL语句中的子查询应用  8.5.1 子查询在INSERT语句中的应用  8.5.2 子查询在UPDATE语句中的应用  8.5.3 子查询在DELETE语句中...

    浅析被遗忘的SQLServer比较运算符修饰词

    SQLServer中有三个关键字可以修改比较运算符:All、Any和Some,其中Some和Any等价。官方的参考文档http://technet.microsoft.com/zh-cn/library/ms187074(SQL.90).aspx 他们作用于比较运算符和子查询之间,作用类似...

    T-SQL高级查询

    # some、any、all子句查询示例 查询班级的学生年龄大于班级的学生的年龄的信息 select * from student where cid = 5 and age > all ( select age from student where cid = 3 ); select * from student where ...

    MySQL中列子查询与行子查询操作的学习教程

    MySQL 列子查询及 IN、ANY、SOME 和 ALL 操作符的使用 MySQL 列子查询 列子查询是指子查询返回的结果集是 N 行一列,该结果通常来自对表的某个字段查询返回。 一个列子查询的例子如下: SELECT * FROM article ...

Global site tag (gtag.js) - Google Analytics