SQL中Union,Intersect,Except的区别
来源:互联网 发布:盗墓java 编辑:程序博客网 时间:2024/04/28 04:58
一、SQL中Union、Intersect、Except的含义
1、Except返回两个结果集的差(即从左查询中返回右查询没有找到的所有非重复值)。
2、Intersect返回 两个结果集的交集(即两个查询都返回的所有非重复值)。
3、union返回两个结果集的并集。
二、限制条件
(1)所有查询中的列数和列的顺序必须相同。
(2)比较的两个查询结果集中的列数据类型可以不同但必须兼容。
(3)比较的两个查询结果集中不能包含不可比较的数据类型(xml、text、ntext、image 或非二进制 CLR 用户定义类型)的列。
(4)返回的结果集的列名与操作数左侧的查询返回的列名相同。ORDER BY 子句中的列名或别名必须引用左侧查询返回的列名。
(5)不能与 COMPUTE 和 COMPUTE BY 子句一起使用。
(6)通过比较行来确定非重复值时,两个 NULL 值被视为相等。(EXCEPT 或 INTERSECT 返回的结果集中的任何列的为空性与操作数左侧的查询返回的对应列的为空性相同)
三、SQL中Union、Intersect、Except实例
create table t1(id int,mark char(2))gocreate table t2(id int,mark char(2))goinsert into t1 select 1,'t1' union all select 2,'t2' union all select 3,'t3' union all select 4,'t4'goinsert into t2 select 2,'t2' union all select 3,'m3' union all select 5,'m5' union all select 6,'t6'goselect * from t1EXCEPTselect * from t2goselect * from t1INTERSECTselect * from t2go--EXCEPT结果集为--1 t1--3 t3--4 t4--INTERSECT结果集为--2 t2
参考资料: SQL中Union,Intersect,Except http://www.studyofnet.com/news/734.html
0 0
- SQL中Union,Intersect,Except的区别
- SQL中union,except,intersect使用方法
- SQL中union, EXCEPT 和 INTERSECT使用方法
- SQL基础--UNION EXCEPT INTERSECT
- SQL中浅谈union、union all、Intersect、Minus的区别
- sql里面EXCEPT、INTERSECT的区别
- sql之union,intersect,except语句
- SQL基础——UNION, EXCEPT, INTERSECT
- LINQ to SQL语句 Union/Intersect/Except
- SQL中 EXCEPT、INTERSECT用法
- SQL中 EXCEPT、INTERSECT用法
- UNION, INTERSECT, EXCEPT
- UNION, INTERSECT, EXCEPT
- 常用SQL查询语句 Oracle中Union,Union All,Intersect,Minus的有什么区别
- Oracle中union、union all、minus和intersect的区别
- SQL Server 2005中Except和Intersect的用法示例
- SQL Server 中关于EXCEPT和INTERSECT的用法
- SQL Server 中关于EXCEPT和INTERSECT的用法
- 棋盘覆盖
- dns+重定向
- 为SharePoint 2010 Workflow 开发 Custom(自定义的) Workflow Activity
- 1 最短路径算法
- LeetCode144 Binary Tree Preorder Traversal
- SQL中Union,Intersect,Except的区别
- 老码识途 函数指针
- 我要读的C语言书籍(电子版百度云下载)
- (素材源码)猫猫学IOS(七)UI之UITextField代理事件_类似QQ登陆窗口的简单实现
- leetcode 题解 || Remove Element 问题
- 看数据结构写代码(24) 二叉链表的递归遍历 和 非递归遍历 算法 总结
- [IOS 开发] frame与bounds的区别比较
- 《VxWorks学习笔记》——实时系统
- 工作可以暂时缓缓。找女朋友要紧呐!