insert into ... select 后面能不能使用union
for example:
insert into sa
select id1 from mytable
union
select id2 from mytable
union
select id3 from mytable
但是,这样的结果是后面两个select没有用处。
...全文
845打赏收藏
insert into ... select
insert into ... select 后面能不能使用union for example: insert into sa select id1 from mytable union select id2 from mytable union select id3 from mytable 但是,这样的结果是后面两个select没有用处。
揭贴
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,导致相同的结果只出现一次。
谢谢四位大哥。
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
你可以创建视图
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