我有两个表结构完全相同,一个是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          1score1
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这四个字段是联合主键,请各们大侠帮忙!谢谢! 

解决方案 »

  1.   

    如果没有重复的直接insert就可以了insert score select * from score1
      

  2.   

    select * from (select * from score union select * from score1) t
      

  3.   

    select * into 新表 from
    (
    select * from score
    union all
    select * from score1
    )t
      

  4.   

    --tryinsert 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)
      

  5.   

    如果不要合并相同记录 就用union all
    如果相同记录合并 就用union
      

  6.   

    谢谢大侠们,你们给的答案我都试了试,都达不到理想的效果,都还有重复值,marco08(天道酬勤)的答案和jacobsan(梅)的答案是对的,score表里有重复值!