I have two tables like
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
Here I want to update sal column in emp table
update emp
set sal = d.sal
from emp as e
left join dept as d on e.deptno = d.deptno
After executing that query I am getting
id name sal deptno
------------------
1 a 100 10
2 b 200 20
3 c 200 20
but I want
id name sal deptno
------------------
1 a 100 10
2 b 200 20
3 c 300 20
try this one :
update emp
set sal = d.sal
from emp as e
left join dept as d on e.id = d.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With