Replacing sql column value based on another table column

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

table definitions

Now I need to replace the col2 values ​​of table1 with the corresponding col1 and col2 values ​​from table2. To make the final table look like this. How can we do this in a request?

Final table

+4
source share
1 answer

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) 
+10
source

Source: https://habr.com/ru/post/1432085/


All Articles