日期:2014-05-18  浏览次数:20502 次

两表相加(表中是联合主键)
我有两个表结构完全相同,一个是score,另一个是score1,我想把这两个表中的数据弄到一个表里!
score  
student_no   km_name   test_type   xq_name   xl1   xl2...xl20   score_flag     protect_f
20060026         数学             1             06-07         8     5       .....           1                     1
20060027         语文             1             06-07         9     6       .....           1                     1

score1
student_no   km_name   test_type   xq_name   xl1   xl2...xl20   score_flag     protect_f
20050036         英语             1             06-07         10     8       .....           1                     1
20050038         地理             1             06-07         11     6       .....           1                     1

其中student_no   ,km_name   ,test_type   ,xq_name这四个字段是联合主键,请各们大侠帮忙!谢谢!  


------解决方案--------------------
select * from (select * from score union select * from score1) t
------解决方案--------------------
select * into 新表 from
(
select * from score
union all
select * from score1
)t
------解决方案--------------------
--try

insert score
select * from score1 as tmp
where not exists(select 1 from score
where student_no=tmp.student_no and km_name=tmp.km_name and test_type=tmp.test_type and xq_name=tmp.xq_name)