0
Table1
ID  | Name         | Mobile     | Gender | Company | ...
104 | Mahesh Akula | 0123456789 | M      | XYZ     | ...

Table2
ID  | Name         | Mobile      | Gender | Company | ...
104 | Mahesh Akula | 85236955545 | M      | ABC     | ...

Table1 should be updated from table2

Note: Both tables will have n number of records

  • Check for old questions. It has already been answered. http://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match – Marc Guillot Apr 18 '17 at 10:30
  • Possible duplicate of [SQL update query using joins](http://stackoverflow.com/questions/982919/sql-update-query-using-joins) – Stefano Zanini Apr 18 '17 at 10:32
  • Next time post tables as well formatted text, not as images, because links may break – Stefano Zanini Apr 18 '17 at 10:35
  • it should reflect for n number of records in table1 at a time with existing ID (Updation of multiple records at a time) – Mahesh Akula Apr 18 '17 at 10:40
  • All the answers will do that, all table1 rows with an ID that exists in table2 will be updated – Stefano Zanini Apr 18 '17 at 10:44
  • Good! If any answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Stefano Zanini Apr 18 '17 at 11:09

5 Answers5

2

Try this

UPDATE t1
SET t1.field_name = t2.field_name
    ,t1.field_2 = t2.field_2
FROM table_1 t1
INNER JOIN table_2 t2 ON t1.id = t2.id
Shiju Shaji
  • 1,682
  • 17
  • 24
0

You can use the update function combined with a join this way

update  t1
set     t1.name = t2.name,
        t1.gender = t2.gender,
        t1.mobile = t2.mobile,
        t1.company = t2.company
from    table1 t1
join    table2 t2
on      t1.id = t2.id
Stefano Zanini
  • 5,876
  • 2
  • 13
  • 33
0

This should work..

UPDATE T1
SET T1.Name=T2.Name,T1.Mobile=T2.Mobile,T1.Gender=T2.Gender,T1.Company=T2.Company
FROM Table1 T1 inner join Table2 T2 on T1.ID=T2.ID
Rajesh Bhat
  • 791
  • 3
  • 8
  • 20
0

you can directly UPDATE table1 form table2 in below format :

 UPDATE Table1 
 SET Table1.Name = T2.Name,Table1.Mobile=T2.Mobile,
     Table1.Gender = T2.Gender,Table1.Company=T2.Company
 FROM Table2 T2 ON T1.ID=T2.ID
Mansoor
  • 4,061
  • 1
  • 17
  • 27
0

Use below code. You will get correct result

update test

set test.Description=test2.description

from test

inner join test2 on test.Id=test2.id