我想填充表中的一个字段,使用另一个表充当查找表的数据,但是看起来似乎不工作无限期地运行表示欢迎。用于从另一个表中的匹配字段更新字段的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
是你想要的伎俩。
“似乎无限期运行”是什么意思?需要更多的上下文。 –