Update Columns in Database

Posted on Friday, January 28th, 2011 at 8:20 pm in

It’s pretty common to want to update a column (or several columns) in one table with the value(s) from another table. Here is how to do it:

UPDATE
    Table
SET
    Table.col1 = other_table.col1,
    Table.col2 = other_table.col2
FROM
    Table
INNER JOIN
    other_table
ON
    Table.id = other_table.id 
WHERE ...

The structure of this syntax is always something I get mixed up when I want to do this.

Top