I'm developing a database and I using 2 specific tables in this problem, being Artwork (ArtworkID, Price, PurchaseID) and Purchase (PurchaseID, Total)
I want to add together the Artwork.Price of the artworks that have the same Artwork.PurchaseID (specifically the ID 'D4758', though I would like the program to be able to total all PurchaseID in the same query).
I then want the added together prices to be placed into Purchase.Total under the corresponding Purchase.PurchaseID row
I've tried multiple ways but I keep getting an SQL syntax error supposedly on Line 3, I've tried changing Artwork to Purchase but I still get it. I'm fairly new to Joins so I'm not sure what to do. Below is the code I developed:
UPDATE Purchase
SET Purchase.Total = SUM(Artwork.Price)
FROM Artwork
INNER JOIN Artwork ON Purchase.PurchaseID = Artwork.PurchaseID
WHERE Artwork.PurchaseID = 'D4758';
The result should change Purchase.Total from NULL to the decimal (5,2) SUM value of Artwork.Price that has a PurchaseID of 'D4758'.
I instead get the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Artwork INNER JOIN Artwork ON Purchase.PurchaseID = Artwork.PurchaseID WH' at line 3