/ Published in: SQL
Update one table by selecting from another. Avoids cursors.
Expand |
Embed | Plain Text
-- Update one table from another USE db_name UPDATE d SET col3 = s.col3, col4 = s.col4 FROM tbl_src AS s, tbl_dest AS d WHERE ((s.col3 IS NOT NULL) AND (s.col4 IS NOT NULL)) AND ((s.pk1 = d.pk1) AND (s.pk2 = d.pk2))
Comments
Subscribe to comments
You need to login to post a comment.

Not working in MySQL...
Alternative for MS Access:
UPDATE tbldest INNER JOIN tblsrc ON tbldest.pk1 = tblsrc.pk1 AND tbldest.pk2 = tblsrc.pk2 SET tbldest.col3 = tblsrc.col3, tbldest.col4 = tblsrc.col4;