Updating a table based on joining another table
suggest changeYou 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents