Updating one table from another sql server

Alias Link FROM POLLINGPLACES A, VOTECENTERS B WHERE A. CODEPLACE Thanks, Colby UPDATE POLLINGPLACES SET PLACE =B.

works fine when I try to update all the records in tbl A, however, in this case I only have missing data which I have identified and populated in tbl B.

When the subquery fails to find a matching row in tbl B, the subquery returns NULL.

If this happens, the UPDATE will terminate with an error ("subquery may return only one row").

UPDATE My Table SET Column1 = (SELECT Some Column FROM Some Other Table WHERE Such And Such = This And That), Column2 = (SELECT Some Other Column FROM Some Other Table WHERE Such And Such = This And That), ... FROM My Table INNER JOIN Some Other Table ON My Table. This And That WHERE Primary Key Column = Some Value Bear in mind that updating data in one table with data from another table may be a sign of bad database design.

But since the UPDATE has no WHERE clause, it will update all rows, even those where the subquery returns NULL.

Consequently, to prevent this, you might do this: One potential issue may arise when the subquery actually finds more than one matching row in tbl B.

For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table.

You must have an account to comment. Please register or login here!