Gems Blog

Click on the gem to start...

October 31, 2013

T-SQL: How to update a table using an INNER JOIN

Filed under: T-SQL,Trick — jmonta82 @ 4:22 pm

Hi folks,

This is an annotation to not forget how to do this on T-SQL that I’m sharing with you.

Could be possible that you want to update a table in T-SQL but only for a subset of records matching another table you want to join with.

So… Here’s an example for this:

 

UPDATE tableA
  SET tableA.yourfield = value 
  FROM tableA AS a INNER JOIN tableB AS b 
  ON a.id=b.id

 

Enjoy!

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.