Wednesday, November 4, 2009

Update using Join and where clause

Its more often required to update a table which value comes from another table and you want to update using joins and specifying the where clause instead of using sub queries.

So here the systax for doing it in SQL server 2008.

update a
set a.[ColName] = b.[ColName]
from [FirstTableName] a inner join [SecondTableName] b
on b.[colName] = a.[ColName]
where a.[colName] > 287


I suppose that a.[colName] is any integer column.

So thats the way update works using joins.