I am trying to update the "Price" field of a table named "Products" in this example with the "Quantity" field from another table called "OrderDetails. I use t as a temporary table to store my query results from OrderDetails, then INNER JOIN the two tables (p and t). I'm still getting error. I validated the query piece (SELECT ...... GROUP BY ProductID) works. It's the UPDATE that is throwing error. Any thought?
UPDATE p
SET Price = t.sumQuan
FROM Products AS p
INNER JOIN
(
SELECT ProductID, SUM(Quantity) sumQuan
FROM OrderDetails
GROUP BY ProductID
) t
ON t.ProductID = p.ProductID;