Updating a table based on joining another table

suggest change

You can also update data in a table based on data from another table:

UPDATE person 
SET state_code = cities.state_code 
FROM cities
WHERE cities.city = person.city;

PostgreSQL has no UPDATE ... JOIN syntax. FROM joins cities so the city’s state code can be copied into person.state_code. Qualify person.city: an unqualified city is ambiguous because cities has the same column. If several cities rows match one person, which row is used is not defined.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents