Sub Query Update:
if you want to run update query in join or by comparing other table then here is the example.
UPDATE Table1 SET Price = Price * 2 WHERE ProductID IN (SELECT ID FROM Table2 WHERE ID= 51); GO
Here is an equivalent UPDATE statement using a join:
USE AdventureWorks; GO UPDATE Table1 SET Price = Price * 2 FROM Table1 AS t1 INNER JOIN Table2 AS t2 ON t1.ProductID = t2.ProductID AND t2.ID= 51; GO
Filed under: SQL Subquery, Stored Procedures | Tagged: Microsoft SQL server, MSSQL, MSSQL server, SQL Server, SQL update with join, Sub Query Update, tow table update, UPDATE statement using a join |
[…] update subquery This may help you: https://sqlhelp.wordpress.com/2008/12…-query-update/ Raghu MCP « Need to optimize query… | Calculation to […]
Hey there, You have done an incredible job. I will certainly digg it and personally recommend to my friends. I’m sure they will be benefited from this website.
I have desired to write something similar to this on my webpage and this has given me a concept. Cheers.