PostgreSQL – Update one table from another

Below is the syntax to update columns of one table from columns of another table in Postgres database.

UPDATE table1 t1
SET t1.c1=t2.c1,
    t1.c2=t2.c2,
    t1.c3=t2.c3
FROM table2 t2
WHERE t1.id=t2.id;

Here table1 is the table being updated. table2 is the table which has the required data for updates. c1,c2,c3 are the columns being updated and exist in both the tables and id is the column used to join the two tables.

See also  PostgreSQL - SUM Function