Posted By

mafro on 11/23/07


Tagged

update


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

vali29
brent-man
uisluu
salmanMd
goo


Update Select


 / Published in: SQL
 

Update one table by selecting from another. Avoids cursors.

  1. -- Update one table from another
  2.  
  3. USE db_name
  4.  
  5. UPDATE d
  6.  
  7. SET col3 = s.col3,
  8. col4 = s.col4
  9.  
  10. FROM tbl_src AS s, tbl_dest AS d
  11. WHERE ((s.col3 IS NOT NULL) AND (s.col4 IS NOT NULL)) AND
  12. ((s.pk1 = d.pk1) AND (s.pk2 = d.pk2))

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Yeah on January 18, 2008

Not working in MySQL...

Posted By: mafro on March 20, 2008

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;

You need to login to post a comment.