Sometimes we may need to update some columns in a table in SQL with values from columns of another table. For this purpose we can use inner join with update query as below.
- UPDATE t1
- SET t1.somecol1 = t2.somecol2
- FROM table1 t1
- INNER JOIN table2 t2 ON t1.id = t2.id
With above query, column 'somecol1' of table1 will be updated with values from 'somecol2' of table2 satisfying the inner join condition.