Update from select


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. TO just SET TO a predetermined VALUE (TRUE, FALSE, 1, 'foo', etc.)
  2.  
  3. UPDATE tblDestination
  4. SET tblDestination.col=VALUE
  5. WHERE EXISTS (
  6. SELECT col2.value
  7. FROM tblSource
  8. WHERE tblSource.join_col=tblDestination.join_col
  9. AND tblSource.constraint=VALUE
  10. )
  11.  
  12. More advanced (sets VALUE TO VALUE IN secondary SELECT statement):
  13.  
  14. UPDATE tblDestination
  15. SET tblDestination.col=(SELECT col2.value FROM tblSource WHERE tblSource.join_col=tblDestination.join_col AND tblSource.constraint=VALUE)
  16. WHERE EXISTS (
  17. SELECT col2.value
  18. FROM tblSource
  19. WHERE tblSource.join_col=tblDestination.join_col
  20. AND tblSource.constraint=VALUE
  21. )

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.