表A,表B 结构相同
表A数据:                           表B数据
字段1   字段2   字段3   字段4        字段1   字段2   字段3   字段4        
张三     aa     123     100          张三    aa             100
李四     aa     234     101          tom     bb             100
tom      bb     147     100现在将表B中的数据放到表A中, 使表A表中的数据变成:
张三  aa   123  100
tom   bb   147  100
应该怎么实现?高手帮忙!!!

解决方案 »

  1.   

    1、delete from a where a.字段1 not in (select 字段1 from b)
    2、Update a set 字段2= (select 字段2 from b where b.字段2 is not null and b.字段1 = a.字段1)
    2、Update a set 字段3= (select 字段3 from b where b.字段3 is not null and b.字段1 = a.字段1)
    2、Update a set 字段4= (select 字段4 from b where b.字段4 is not null and b.字段1 = a.字段1)
      

  2.   

    1、delete from a where a.字段1 not in (select 字段1 from b)
    2、
    update a set 字段2=b.字段2,字段4=b.字段4
    from a,b
    where a.字段1=b.字段1
      

  3.   

    如果要把表B中的一条记录,在表A中没有,现在要把这条记录加到表A中,怎么办?
      

  4.   

    insert into a(字段1 ,  字段2,   字段3,   字段4 ) 
    select * from b where b.字段1 is not in (select 字段1 from a )