加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLServer 表查询中的 合并查询 合集 差集 交集

发布时间:2020-12-12 15:27:12 所属栏目:MsSql教程 来源:网络整理
导读:use tempdb go if (object_id ('t1' ) is not null ) drop table t1 if (object_id ('t2' ) is not null ) drop table t2 go create table t1 (a int ) insert into t1 select 1 union select 2 union select 3 create table t2 (a int ) insert into t2 sel

use tempdb
go
if (object_id ('t1' ) is not null ) drop table t1
if (object_id ('t2' ) is not null ) drop table t2
go
create table t1 (a int )
insert into t1 select 1 union select 2 union select 3
create table t2 (a int )
insert into t2 select 3 union select 4 union select 5
go
select * from t1 union select * from t2
go
/* 求表合集
1
2
3
4
5*/
select * from t1 union all?? select * from t2
go
/*求表合集不过滤重复
1
2
3
3
4
5*/
select * from t1 except select * from t2
go
/*求t1对t2的差集
1
2*/
select * from t1 intersect select * from t2
go
/*求t1对t2的交集
3*/

本文来自CSDN博客:http://blog.csdn.net/jinjazz/archive/2009/09/07/4527863.aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读