合并查询结果

the_Fm 2003-01-06 10:43:22
在MSSQL自带的pubs中执行如下查询
USE pubs
select * from authors where au_id like '%72%'
select * from authors where contract='1'

现在希望将两条SELECT的结果合并(以or的方式,如果又相同的结果只取一个)
例如
=====
select * from authors where (au_id like '%72%') or (contract='1')

希望能给予另外一种方法,就是将这些查询结果先添加到某个临时表里,然后一次查询出来,可能吗?(如果你问为什么,原因是,那样做程序好写得多)
...全文
38 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
happydreamer 2003-01-06
  • 打赏
  • 举报
回复
select * into #temp from authors where au_id like '%72%'

insert into #temp select * from authors where au_id like contract='1'
gzh_seagull 2003-01-06
  • 打赏
  • 举报
回复
create table #tmp
select * into #tmp from authors where au_id like '%72%'
select * into #tmp from authors where au_id like contract='1'
select * from #tmp

drop table #tmp
the_Fm 2003-01-06
  • 打赏
  • 举报
回复
select * into #temp from authors where (au_id like '%72%') or (contract='1')

我的确希望使用select into 可是希望的是
select * into #temp from authors where au_id like '%72%'
select * into #temp from authors where au_id like contract='1'
select * from #temp

drop table #temp

系统的提示是#temp已经存在
如果只用一句sql好像不能简化我的工作
hjhing 2003-01-06
  • 打赏
  • 举报
回复
select * into #temp from authors where (au_id like '%72%') or (contract='1')

select * from #temp

drop table #temp
OpenVMS 2003-01-06
  • 打赏
  • 举报
回复
select distinct * from (
select * from authors where au_id like '%72%'
union all
select * from authors where contract='1') a

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧