我想update表table1的a1,a2字段 这两个字段是table2里的b1(字符串字段),b2
table1 和table2 的关系是1对2我想把table2里两行b1,b2中的一行update到table1里update table1 t1 set (t1.a1,t1.a2)=
(select t2.b1,t2.b2
from table2 t2)
where t1.id=t2.id and rowmun<=1
;
请问
这样可以吗?
table1 和table2 的关系是1对2我想把table2里两行b1,b2中的一行update到table1里update table1 t1 set (t1.a1,t1.a2)=
(select t2.b1,t2.b2
from table2 t2)
where t1.id=t2.id and rowmun<=1
;
请问
这样可以吗?
set t1.a1=t2.b1,t1.a2=t2.b2
from table1 t1,table2 t2
where t1.id=t2.id and rowmun<=1
--修改
Update Table1 Set a1 = (select t2.b1,t2.b2
from Table2 t2 Where rowmun<=1),a2 = (select t2.b2
from Table2 t2 Where rowmun<=1)--添加
Insert Into Table1 (a1,a2) Select b1,b2 From Table2 Where RowNum <=1--另外一种方法
Declare @b1 varchar(20),@b2 varchar(20)
Select @b1 = b1 ,@b2 = b2 From Table2 where rowmun<=1
Update Table1 Set a1 = @b1,a2=@b2 Where rownum <=1
set t1.a1=t2.b1,t1.a2=t2.b2
from table1 t1,table2 t2
where t1.id=t2.id and rowmun<=1
set t1.a1=t2.b1,t1.a2=t2.b2
from table1 t1,table2 t2
where t1.id=t2.id and rowmun<=1
update table1 t
set (a1,a2) = (select b1,b2 where from table2 where id=t.id and rownum=1);