-2

i have 2 tables EmployeeData and employeePersonalData.

I have common column emailId.

Now I want copy all the emailId from employeeData to employeePersonalData how can I do?

sruthy c.k
  • 17
  • 6
  • 1
    how are the two tables joined together. When you say copy do you want to update the target column or you want to insert a new row? – Amit Sukralia Mar 22 '16 at 10:20
  • Your question is a bit confusing. Do you want to only copy the ID and leave all other columns blank? Is this an update or an insert? – Tim Biegeleisen Mar 22 '16 at 10:21
  • yes i want to copy only the mailid column. And the mailid column in employeePersonalData already have data ,i want to update the whole data with employeeData table – sruthy c.k Mar 22 '16 at 10:50

2 Answers2

1

you can visit similar question

It provides us two approach.

Before that please check you should be having one more common column similar to EmployeeId in both the tables.

so then you can use either of below approach -

1) using UPDATE FROM with a JOIN will help

Update employeePersonalData 
   set employeePersonalData.emailId =employeeData.emailId 
  from employeePersonalData  inner join employeeData b 
    on employeePersonalData.emploeeId =employeeData.employeeId

2) Using merge

MERGE INTO employeePersonalData
   USING employeeData
      ON employeePersonalData.emailId =employeeData.emailId 
WHEN MATCHED THEN
   UPDATE 
      SET employeePersonalData.emailId =employeeData.emailId;
Community
  • 1
  • 1
pratik garg
  • 3,282
  • 1
  • 17
  • 21
0

Update a set a.emailId =b.emailId from employeePersonalData a inner join employeeData b on a.emailId =b.emailId

Antony
  • 966
  • 8
  • 19