google

SQL Server Update statement with Joins and Where clause

| Thursday, February 27, 2014
Update statement of MS SQL server is used to update the tuples or set of tuples in a table. Update statement can also be used with joins to update the values from one table into another table as follows.
UPDATE  Customer
SET BrandName= BrandNameMaster.Id
from Customer Inner Join BrandNameMaster on
BrandName=BrandNameMaster.Name




This will update the "BrandName" column of the "Customer" table with the values of "Id" columns from the "BrandNameMaster" table based on the Inner join condition on columns "BrandName" of "Customer" table and "Name" column of "BrandNameMaster" table.

We can also additionally use where statement with such Update statement as follows.

UPDATE  Customer
SET BrandName= BrandNameMaster.Id
from Customer Inner Join BrandNameMaster on
BrandName=BrandNameMaster.Name

where  BrandName='Nike'










 If you have used any other variations of update statement, Please post in the comments.

Thanks 

0 comments:

Post a Comment

Next Prev
▲Top▲