Skip to content
Advertisement

Updating only specific rows within the lowest value

I’m trying to update different rows in my table.

I got a table called: table_price_product

this table contains all the information related to different products

NOTE: inside this table you will see different rows for the same product (or not) because it contains all the prices for all products (old and new ones)

Every item_code has a different “request_id”, the newest row will have the highest value.

Take a look at this table:

This is my sqlfiddle

I want to create an UPDATE script in order to modify the item_codes within the lowest request id

In this case, the item_code: ‘99342435’ has 2 rows: one with the request_id = ‘42937536’ and the other one with the request_id = ‘42937524’. I would like to update the row with the lowest request_id and set the attribute ‘status’ = ‘150’

IMAGE


I would like to obtain this output:

I tried to do something like this but it did not work.:

max(request_id) over (partition by item_code) as max_request

Can help me to solve this?

EDIT#1: i’m using Oracle database



EDIT: I could have this scenario:

I would like to obtain this:

Advertisement

Answer

You can try the following.

Update using min()

After update statement when you do select as following then you get your output as expected.

Output:


EDIT: I could have this scenario:

|ITEM_CODE |PRICE |START_DATE_ACTI

I would like to obtain this:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement