我有两张表
A表 2个字段 id和value
B表 2个字段 id和valueA,B两表的id有一部分是相同的
当B.id=A.id时,把对应的A.value的值改成B.value的值
SQL语句怎么写,请教高手
A表 2个字段 id和value
B表 2个字段 id和valueA,B两表的id有一部分是相同的
当B.id=A.id时,把对应的A.value的值改成B.value的值
SQL语句怎么写,请教高手
如果有更新的话 还得加个trigger
where exists (select 1 from b where a.id=b.id)
MERGE INTO a
USING b
ON (a.id = b.id)
WHEN MATCHED THEN
UPDATE SET a.value = b.value;
when matched then update set A.value=B.value
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