0

Update Query said ORDER_DETAILS.QUANTITY is an invalid identifier. I check and there is a table named ORDER_DETAILS with a field named QUANTITY.

Error at Command Line : 14 Column : 57
Error report -
SQL Error: ORA-00904: "ORDER_DETAILS"."QUANTITY": invalid identifier
00904. 00000 -  "%s: invalid identifier"

///////////////////////////////////////////////

UPDATE 
(SELECT Orders.Order_ID, Order_Details.Quantity, Products.Units_In_Stock, Orders.Shipped_Date, Orders.This_Order_Was_Shipped
FROM Products 
INNER JOIN Orders 
INNER JOIN Order_Details ON Orders.Order_ID = Order_Details.Order_ID ON Products.Product_ID = Order_Details.Product_ID
WHERE ((Orders.Shipped_Date Is Not Null) AND (Orders.This_Order_Was_Shipped='YES'))) 
SET Products.Units_In_Stock = Products.Units_In_Stock - Order_Details.Quantity;           
2
  • I know that the select query above work because it returns three records as I expected. I just need to get it to update properly. SELECT Orders.Order_ID, Order_Details.Quantity, Products.Units_In_Stock, Orders.Shipped_Date, Orders.This_Order_Was_Shipped FROM Products INNER JOIN Orders INNER JOIN Order_Details ON Orders.Order_ID = Order_Details.Order_ID ON Products.Product_ID = Order_Details.Product_ID WHERE ((Orders.Shipped_Date Is Not Null) AND (Orders.This_Order_Was_Shipped='YES'));
    – Lynn
    Commented Sep 18, 2017 at 15:33
  • 1
    stackoverflow.com/questions/tagged/oracle+sql-update+join
    – user1822
    Commented Sep 18, 2017 at 18:05

1 Answer 1

1

For reference, this is a continuation of the following post. How to convert an Update a query from MS Access to Oracle SQL Software

I kind of wish you would have continued our conversation there, but I guess they can be merged somehow.

I think you might have taken what I said literally and just switched ORDER DETAILS table to ORDER_DETAILS in your SELECT statement instead of changing the actual object's name.

The object's name was [ORDER DETAILS] and needs to be identified as "ORDER DETAILS" in ORACLE (with Quotes instead of brackets). Try that and see.

If not, and you actually did change the table itself to ORDER_DETAILS, then your issue is that you're using ORDER_DETAILS.Quantity in your SET. That is not appropriate. You NEED to give the subquery that the UPDATE wraps an ALIAS and say:

SET Alias.OldValue = Alias.NewValue

You should set up your SELECT to retrieve the OldValue of the column, and the NewValue of the column. Please see the link I included in my original answer: https://stackoverflow.com/questions/2446764/update-statement-with-inner-join-on-oracle

2
  • 2
    It's a continuation of a continuation ... Commented Sep 18, 2017 at 21:23
  • 2
    @ypercubeᵀᴹ Taking "subqueries" in the literal sense. :)
    – SQLDevDBA
    Commented Sep 18, 2017 at 22:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.