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,
FROM table2 t2

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 - Connect to database from command line using password