SQL Server UPDATE JOIN

By | November 28, 2019
UPDATE Table1
SET    column1 = T2.column1,
       column2 = T2.column2
FROM   #Table1 T2
       JOIN #Table2 T2
         ON T1.Column3 = T2.Column3

Lets say we have employee & ProjectTeam table as below respectively,

Id Name Address PhoneNumber
11 Ajay Mumbai 887
12 Jatin Pune 356
ProjectId EmpId PhoneNumber
P123 11  
X234 12  

So now we want to update employee phone number in projectteam table from employee table. So SQL statement would be like,

UPDATE 
       ProjectTeam
SET    
       PhoneNumber = Emp.PhoneNumber
FROM   
      #ProjectTeam PT
JOIN  
       #Employee Emp 
ON 
      PT.EmpId = Emp.Id