0

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;
3
  • What is the error message? Commented Feb 16, 2017 at 22:06
  • 2
    Possible duplicate of Access DB update one table with value from another Commented Feb 16, 2017 at 22:09
  • @xQbert The error I received is Syntax error in UPDATE statement which I cannot figure out. I read a few topics around this on Stackoverflow and I still don't know where I did wrong. If someone can help me with some pointers would be great. Commented Feb 17, 2017 at 0:14

1 Answer 1

2

Maybe just a syntax variance with Access vs other RDBMS?

UPDATE products 
INNER JOIN (SELECT ProductID, SUM(Quantity) sumQuan
            FROM OrderDetails
            GROUP BY ProductID 
           ) t
  ON t.ProductID = p.ProductID;
SET Price = t.sumQuan
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.