如何用update from TABLE 1
ID C1 C2 C3
1 XX YY ZZ
2 XX1 YY1 ZZ1
3 XX2 YY2 ZZ2
TABLE 2 把C1C2C3 通过表1 放进去
ID C1 C2 C3
1
2
3
如何用 update from啊
我写的是
update table2 set c1=(select top 1 c1 from table1 where id =table2.id),
c2=(select top 1 c2 from table1 where id =table2.id)
c3=(select top 1 c3 from table1 where id =table2.id)
这种方法很死,而且没有效率
我想用
update table2
set c1=t.c1,c2=t.c2,c3=t.c3
from (select top 1 c1,c2,c3 from table1 where id=table1.id ) t
为什么不行。报错。。。 ------最佳解决方案--------------------
UPDATE b
SET b.c1 = a.c1 ,
b.c2 = a.c2 ,
b.c3 = a.c3
FROM TABLE1 a
INNER JOIN TABLE2 b ON a.id = b.id
------其他解决方案-------------------- update table2 set C1=b.c1,c2=b.c2,c3=b.c3
from table2 as a inner join table1 as b on a.id=b.id ------其他解决方案-------------------- update table2
set c1=t.c1,c2=t.c2,c3=t.c3
from (select top 1 c1,c2,c3 from table1 where id=table1.id ) t