我有两张表,比如
emp
:
id name sal deptno
-------------------
1 a x 10
2 b x 20
3 c x 20
dept
:
id sal deptno
-------------
1 100 10
2 200 20
3 300 20
在此,我想更新sal
表格中的emp
列
update emp
set sal = d.sal
from emp as e
left join dept as d on e.deptno = d.deptno
执行该查询后,我正在
id name sal deptno
------------------
1 a 100 10
2 b 200 20
3 c 200 20
但我想要
id name sal deptno
------------------
1 a 100 10
2 b 200 20
3 c 300 20
答案 0 :(得分:1)
试试这个:
update emp
set sal = d.sal
from emp as e
left join dept as d on e.id = d.id