用于从另一个表中的匹配字段更新字段的SQL

时间:2013-07-15 20:20:54

标签: oracle sql-update

我正在尝试使用来自另一个表的数据来填充表中的字段,该表充当查找表,类似于此但它看似无效但似乎无限期地运行建议欢迎。

UPDATE table1 t1
  SET field=(select field2
               FROM table2 t2
               WHERE t1.otherfield=t2.otherfield)

2 个答案:

答案 0 :(得分:2)

在某些情况下,合并声明可以更有效。您也可以尝试以下方法: -

merge into table1 t1
using(select otherfield,field2 from table2)y
on(t1.otherfield=y.otherfield)
when matched then
update set field=y.field2

答案 1 :(得分:0)

UPDATE t1
SET t1.field=t2.field2 
FROM Table1 t1
inner join table2 t2 On t1.otherfield=t2.otherfield

你想要的技巧。

相关问题