SQLUSA
 

Microsoft SQL Server 2000

Best Practices

 

How to do update from two tables?

 

Frequently you have to do update from 2 or more tables. Here is an example.

UPDATE Titles
SET YTDSales = a.YTDSales + b.Quantity
FROM Titles a, Sales b
WHERE a.TitleID = b.TitleID
AND a.OrderDate = (SELECT MAX(OrderDate) FROM Sales )

 

Best in the World in SQL Server Training
 
SQLUSA.com Home Page