我想填充表中的一個字段,使用另一個表充當查找表的數據,但是看起來似乎不工作無限期地運行表示歡迎。用於從另一個表中的匹配字段更新字段的SQL
UPDATE table1 t1
SET field=(select field2
FROM table2 t2
WHERE t1.otherfield=t2.otherfield)
我想填充表中的一個字段,使用另一個表充當查找表的數據,但是看起來似乎不工作無限期地運行表示歡迎。用於從另一個表中的匹配字段更新字段的SQL
UPDATE table1 t1
SET field=(select field2
FROM table2 t2
WHERE t1.otherfield=t2.otherfield)
合併語句在某些情況下可以更有效。您還可以嘗試以下方法: -
merge into table1 t1
using(select otherfield,field2 from table2)y
on(t1.otherfield=y.otherfield)
when matched then
update set field=y.field2
謝謝你工作完美 –
UPDATE t1
SET t1.field=t2.field2
FROM Table1 t1
inner join table2 t2 On t1.otherfield=t2.otherfield
是你想要的伎倆。
「似乎無限期運行」是什麼意思?需要更多的上下文。 –