Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Update Query [duplicate]

Tags:

I have a table T1 which contains three columns: Id, Name, Address

There is another table T2 which contains 2 columns Id, New_Address. Id column of T2 is same as of T1.

I need a query which will update Address column of T1 with New_Address of T2.

I can do it through a loop by checking ID and executing update statement. How can it has to be done with a query?

like image 1000
F11 Avatar asked Feb 23 '13 11:02

F11


2 Answers

How about

UPDATE T1 SET Address = T2.New_Address FROM T2 WHERE T1.id = T2.id 
like image 194
marc_s Avatar answered Sep 21 '22 21:09

marc_s


UPDATE T1 SET T1.Address = T2.New_Address FROM T1 INNER JOIN T2 ON T2.ID = T1.ID 
like image 34
Darren Avatar answered Sep 21 '22 21:09

Darren