insert into ... select

welyngj 2003-09-14 06:11:13
insert into ... select 后面能不能使用union
for example:
insert into sa
select id1 from mytable
union
select id2 from mytable
union
select id3 from mytable
但是,这样的结果是后面两个select没有用处。
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
welyngj 2003-09-14
  • 打赏
  • 举报
回复
揭贴
I made a mistake just now.in fact the sql statements:
insert into sa
select id1 from mytable
union all
select id2 from mytable
union all
select id3 from mytable
能够使用union,只是我开始的时候忘了加all,导致相同的结果只出现一次。
谢谢四位大哥。
mjhnet 2003-09-14
  • 打赏
  • 举报
回复
insert into sa
select * from
(
select id1 from mytable
union
select id2 from mytable
union
select id3 from mytable
)
AAA
benxie 2003-09-14
  • 打赏
  • 举报
回复
用VIEW吧。
tqqonline 2003-09-14
  • 打赏
  • 举报
回复
insert #temp select id1 from mytable
go
insert #temp select id2 from mytable
go
insert #temp select id3 from mytable
go
insert sa select * from #temp
go
friendliu 2003-09-14
  • 打赏
  • 举报
回复
这样也能就是不行的

你可以创建视图
create view test as
select id1 from mytable
union
select id2 from mytable
union
select id3 from mytable
go
insert into .....select * from test
go

34,590

社区成员

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

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