Table1
表格1
ID Loc
-----------
001 null
002 null
003 PYD
004 null
....
Table2
表2
ID Loc
-----------
001 TMB
002 null
003 PYD
004 SHD
....
I want to update table1 from table2. I'd need something like this:
我想从table2更新table1。我需要这样的东西:
update table1 set LoC = Select LoC from table2
And the expected output:
和预期的产量:
Table1
表格1
ID Loc
-----------
001 TMB
002 null
003 PYD
004 SHD
....
How do I update table1 from table2?
如何从table2更新table1?
5 个解决方案
#1
2
try something like:
尝试类似的东西:
update t
set t.loc = t2.loc
from table1 t
inner join table2 t2 on t.id =t2.id
#2
1
update table1 set LoC = (Select LoC from table2 where table2 .ID = table1 .ID)
#3
1
Is that what you need?
这就是你需要的吗?
update table1
set Loc = t2.Loc
from table1 t1 join table2 t2
on t1.ID = t2.ID
#4
1
update table1
set Loc = table2.Loc
from table2
where table1.ID = table2.ID
#5
0
You can use joins.
您可以使用联接。
update t1 set t1.Loc=t2.Loc
From Table1 t1 inner join Table2 t2
on t1.Id=t2.Id
#1
2
try something like:
尝试类似的东西:
update t
set t.loc = t2.loc
from table1 t
inner join table2 t2 on t.id =t2.id
#2
1
update table1 set LoC = (Select LoC from table2 where table2 .ID = table1 .ID)
#3
1
Is that what you need?
这就是你需要的吗?
update table1
set Loc = t2.Loc
from table1 t1 join table2 t2
on t1.ID = t2.ID
#4
1
update table1
set Loc = table2.Loc
from table2
where table1.ID = table2.ID
#5
0
You can use joins.
您可以使用联接。
update t1 set t1.Loc=t2.Loc
From Table1 t1 inner join Table2 t2
on t1.Id=t2.Id