Brian Wilson
Brian Wilson

Reputation: 135

SQL for update price

Im doing homework, and cannot figure out exactly what I need to do:

PROBLEM:

SQL I USED:

UPDATE PART
  set PRICE=PRICE*1.05
ORDER BY ON_HAND DESC;

WHAT I GET IN RETURN:

ERROR at line 3: ORA-00933: SQL command not properly ended

Upvotes: 0

Views: 1929

Answers (4)

heretolearn
heretolearn

Reputation: 6545

If you just have to display the values you could do something like this:

select item,on_hand,price,(price * 1.05) as new_price
from part
order by on_hand desc;

SQLFiddle

But if you have to update the new price in the table and then display the values, you would have to write two queries, one to update the value and second to display the values.

To update the values:

UPDATE PART set PRICE=PRICE*1.05;

To display the values:

select *
from part
order by on_hand desc;

SQLFiddle

Upvotes: 3

Guffa
Guffa

Reputation: 700262

First get the currect values, and calculate the new values:

select PRICE, ON_HAND, PRICE * 1.05 as NEW_PRICE
from PART
order by ON_HAND DESC

Then do the actual update

update PART
set PRICE = PRICE * 1.05

Upvotes: 1

user1864610
user1864610

Reputation:

ORDER BY is not a valid clause in an UPDATE query in Oracle SQL (although MySQL does support it). That's why you're getting the error message. Simply remove the clause

It rarely makes a difference exactly which order an UPDATE is performed in anyway.

The rest of your question will require an ORDER BY clause as part of a SELECT statement

Upvotes: 1

Ilya
Ilya

Reputation: 29693

UPDATE query cann't be used with ORDER BY.

UPDATE PART set PRICE=PRICE*1.05;  

or

UPDATE PART set PRICE=PRICE*1.05 WHERE some_condition;

Upvotes: 3

Related Questions