Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your update statement does not specify which of the records in the "addresses" table to update so records not in the select statement are updating with nothing.

This statement will update only records in "addresses" table which have a corresponding record in "tnumbers" table. This means that if there is a record in the "addresses" table with a "city" = 'OMAHA' but there is NOT a corresponding record in the "tnumbers" table, it will not change.

UPDATE "addresses" SET "AREACODE" = (SELECT "AREACODE" FROM "tnumbers" WHERE "addresses"."ID" = "tnumbers"."ID" AND "tnumbers"."city" = 'OMAHA' ) where EXISTS (SELECT "AREACODE" FROM "tnumbers" WHERE "addresses"."ID" = "tnumbers"."ID" AND "tnumbers"."city" = 'OMAHA' )