将表1
id pw
a 23
b 33
c 44
与表2
id pw
a 55
e 22
d 77
合并成表3
id pw
a 23
b 33
c 44
e 22
d 77
也就是当表2中对应id不存在于表1时,即将数据行复制,否则丢弃,但表1中的id仍保留,我看了一下联结
但好像只能进行列的连接,请各位指教!
id pw
a 23
b 33
c 44
与表2
id pw
a 55
e 22
d 77
合并成表3
id pw
a 23
b 33
c 44
e 22
d 77
也就是当表2中对应id不存在于表1时,即将数据行复制,否则丢弃,但表1中的id仍保留,我看了一下联结
但好像只能进行列的连接,请各位指教!
select
*
from
(
select * from 表1
union all
select * from 表2 where id not in(select id from 表1)
)t
select * from [表1]
union
select * from [表2] where id not in(select id from [表1])
if object_id('c') is not null drop table c
create table c(id char(10),pw char(20))
insert into c(id,pw)
select id,pw from a
union all
select id,pw from b where not exists
(select 1 from a where a.id=b.id)
select * from c
/*
id pw
---------- --------------------
a 23
b 33
c 44
e 22
d 77
*/
select *
from 表2
where id in (
select id from 表2
except
select id from 表1)
insert into viewall
select * from
(
select * from view29
union all
select * from view31 where Col001 not in(select Col001 from view29)
)提示有语法错误-_-!