delete a from a,b where a.id=b.id
insert into A
select b.* from b where b.id  in (select B.id from A,B where A.id =b.id)
要实现的是,先删除a表中的id和b表中id相同的记录,再把b表中的这些记录插入到a表中

解决方案 »

  1.   

    delete a.id from a where a.id=b.id
    insert into A
    select * from b where b.id  in (select B.id from A,B where A.id =b.id)
      

  2.   

    1.delete from a where a.id=b.id
    2.用存储过程和临时表吧!
      

  3.   

    我同意楼上大虾的意见,如果你非要删除后再添加,我建议可以用一个临时表保存一下ID相同的ID
    而后再
    delete a from a,b  where a.id=b.id
    insert into a 
    select b.* from b where b.id in (select temp.id from temp)
      

  4.   

    我能不能这样理解?
    就是吧a表中的和b表中相同的id的数据用b中的数据更新?不要删除再加吧?
      

  5.   

    select * into #t from a
    select * into #t1 from bdelete #t.a from #t,#t1 where #t.id=#t1.id
    insert into b
    select b.* from b where b.id  in (select b.id from #t,b where #t.id =b.id)Drop table #t 
    Drop table #t1
      

  6.   

    update a set a.字段1=b.字段1 ,a.字段2=b.字段2,a.字段3=b.字段3
    from b,a
    where b.id in
    (
      select b.id from b,a where a.id=b.id
    )
      

  7.   

    delete from a where a.id=b.id
    这条语句不对啊!
      

  8.   

    delete from a where a.id  in (select B.id from A,B where A.id =b.id)
      

  9.   

    楼主请再写清楚一点
    先是 delete * from a,b where a.id=b.id
    后面再 insert into A
           select * from b where b.id  in (select B.id from A,B where A.id =b.id)
    括号里边的 select 语句是查不出记录的按照楼住的话:“要实现的是,先删除a表中的id和b表中id相同的记录,再把b表中的这些记录插
                   入到a表中”
    这样子的话就不能“再把b表中的这些记录” 注意是“这些”记录插入到 a 表中,因为“这些”
    记录已经被删除,只能是把剩下的记录插入到 a 表中
    应该是 :
     insert into a
     select * from b