Hey all:
I'm trying to write an SQL update statement for a project. There are three tables that I am working with here: "Books", "Transactions", and "Includes". "Includes" connects the other two tables by the "Order_ID" and "Book_ID" keys.
What I am trying to do here is set the "Total_Amount" column for each "Transaction" to be equal to the sum of the "Price" of all books for which there exists an entry in the "Includes" table that references the Order_ID (of the Transaction) and Book_ID (of the Book).
I'm getting Error 1242/"Subquery returns more than 1 row". I would suppose that the solution is rather simple but cannot get myself to think of it off the top of my head. Any advice would be greatly appreciated..thanks
Here is my code:
I'm trying to write an SQL update statement for a project. There are three tables that I am working with here: "Books", "Transactions", and "Includes". "Includes" connects the other two tables by the "Order_ID" and "Book_ID" keys.
What I am trying to do here is set the "Total_Amount" column for each "Transaction" to be equal to the sum of the "Price" of all books for which there exists an entry in the "Includes" table that references the Order_ID (of the Transaction) and Book_ID (of the Book).
I'm getting Error 1242/"Subquery returns more than 1 row". I would suppose that the solution is rather simple but cannot get myself to think of it off the top of my head. Any advice would be greatly appreciated..thanks
Here is my code:
Code:
update Transactions
set Total_Amount =
(select sum(Price) from Books
where ((select Book_ID from Includes) = Book_ID AND
(select Order_ID from Includes) = Order_ID));