Doing a join in an update in SQL for PostgreSQL

Was writing some SQL queries for PostgreSQL for updating some tables and did a touch of trial and error for getting the syntax right for doing a join within an update statement. Below is how I did it. I’m thinking there should be a neater way.

update table1 set columnZ = newValue from table1 t1
inner join table2 t2
on t1.columnX = t2.columnY
where table1.uniqueID = t1.uniqueID
and t2.filterColumn = filterValue

Advertisement
This entry was posted in Programming Tips and Tricks. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s