查询几张表中并集
select b.* from CorpBasic b where 1=1
and b.ID in(
select CorpID from CorpSMS where 1=1 and RoleID in(-999 ,1)
[b]union[/b]
select CorpID from CorpWap where 1=1 and RoleID in(-999 ,1)
[b]union[/b]
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)
[b]intersect[/b]
select CorpID from CorpWap where 1=1 and RoleID in(-999 ,1)
[b]intersect[/b]
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)
[b]union[/b]
select CorpID from CorpWap where 1=1 and RoleID in(-999 ,1)
[b]union[/b]
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)
[b]intersect[/b]
select CorpID from CorpWap where 1=1 and RoleID in(-999 ,1)
[b]intersect[/b]
select CorpID from CorpComWeb where 1=1 and RoleID in(-999 ,1)
)
本文介绍如何使用SQL查询多个表之间的并集与交集数据。通过具体示例展示了如何利用union和intersect关键字实现跨表数据的组合,适用于需要整合不同来源数据的场景。
1443

被折叠的 条评论
为什么被折叠?



