两个表a,b都有ID和des字段,现在想把b中与a中的ID相同但是des不同的搜索出来,并使得b中的des也变成相应的a中的des。最终目的是让两个表中的id相同的des也相同。

解决方案 »

  1.   

    直接把A中的des同步到B中:
    update b set des=(select des from a where a.id=b.id)只同步不同的项目:
    update b set des=(select des from a where a.id=b.id and a.des<>b.des)
      

  2.   

    update b set des=(select des from a where a.id=b.id and a.des<>b.des) where id in (select id from a)
      

  3.   

    liujia_0421(SnowLover) ( ) 的正解
      

  4.   

    update b set des=(select des from a where a.id=b.id) where id in (select id from a)改成这样最保险..
      

  5.   

    不好意思,细想了一下,应该是上面这个正确,即:update b set des=(select des from a where a.id=b.id) where id in (select id from a)
      

  6.   

    或者这样:update b set des=(select des from a where a.id=b.id) where id in (select id from a where a.des<>b.des)这个最好,已测试通过..