Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update single row in table from multi rows in another table 1

Status
Not open for further replies.

jboo

Programmer
Jan 4, 2001
12
GB
I have 2 tables: Products and Inventory. The Products rows hold an InventoryTotal, which should be a "sum" of Inventory.LocationTotal (for each Product). Can I do a simple query to update the Products.InventoryTotal field with the total of the fields Inventory.LocationTotal by ProductCode? It seems so simple, but it's driving me mad!
 
Have you tried this -

Code:
UPDATE Products
  SET InventoryTotal = (SELECT SUM(LocationTotal)
     FROM Inventory
        WHERE Inventory.ProductID = Products.ProductID)
FROM Products, Inventory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top