首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL话语中的两个常用的关键字:INTERSECT(交集)和UNION(并集)

2012-09-28 
SQL语句中的两个常用的关键字:INTERSECT(交集)和UNION(并集)查询几张表中并集select b.* from CorpBasic b

SQL语句中的两个常用的关键字:INTERSECT(交集)和UNION(并集)

查询几张表中并集
select b.* from CorpBasic b where  1=1
and b.ID in(
select CorpID from CorpSMS  where 1=1  and RoleID in(-999 ,1)
union
select CorpID from CorpWap where 1=1  and RoleID in(-999 ,1)
union
select CorpID from CorpComWeb where 1=1  and RoleID in(-999 ,1)
      )

查询几张表中交集
select b.* from CorpBasic b where  1=1
and b.ID in(
select CorpID from CorpSMS  where 1=1  and RoleID in(-999 ,1)
intersect
select CorpID from CorpWap where 1=1  and RoleID in(-999 ,1)
intersect
select CorpID from CorpComWeb where 1=1  and RoleID in(-999 ,1)
      )

热点排行