我有两张表
A表  2个字段  id和value
B表  2个字段  id和valueA,B两表的id有一部分是相同的
当B.id=A.id时,把对应的A.value的值改成B.value的值
SQL语句怎么写,请教高手

解决方案 »

  1.   

    update a set a.value = (select value from a,b where a.id = b.id)
    如果有更新的话 还得加个trigger
      

  2.   

    update a set value = (select b.value from b where a.id=b.id)
    where exists (select 1 from b where a.id=b.id)
      

  3.   

    --10g及以上可用
    MERGE INTO a
    USING b
    ON (a.id = b.id)
    WHEN MATCHED THEN
      UPDATE SET a.value = b.value;
      

  4.   

    merge into A using B on(B.id=A.id)
    when matched then update set A.value=B.value
      

  5.   


    SQL> select * from t1;        ID      VALUE
    ---------- ----------
             1          3
             2          5SQL> select * from t2;        ID      VALUE
    ---------- ----------
             1          7
             2         10SQL> update t1 set value = (select value from t2 where t1.id = t2.id)
      2  where exists (select 1 from t2 where t1.id = t2.id);2 rows updated.SQL> select * from t1;        ID      VALUE
    ---------- ----------
             1          7
             2         10