Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing a sql column value based on a column another table

I have table1 (col1,col2) and table2(col1,col2) as given below/

table definitions

Now i need to replace values of col2 of table1 with corresponding value of col1 and col2 from table2. So that the final table should look like this. how can we do this in query??

Final table

like image 451
Olivarsham Avatar asked Sep 03 '12 13:09

Olivarsham


1 Answers

I assume table1.col2 and table2.col2 have the same text type(?)

update table1 set table1.col2=table2.col2
from table1 
join table2 on (table1.col2=table2.col1)
like image 160
valex Avatar answered Oct 13 '22 07:10

valex