I need to update values in a table for a subset of rows returned from a select statement. The select statement may return any number of records. I'll use 15 in this example. I want to update the first 9 records returned with the value of "Green" and the remaining records with the value "Yellow". I need the data to be sorted in ascending order by the Order_ID field which is the unique key for the table. nGreen is a variable containing the maximum number of "Green" records.
I've tried something like this:
UPDATE TABLE SET COLOR = 'Green' WHERE ORDER_ID = (SELECT ORDER_ID FROM TABLE WHERE STATUS = 'Open' AND ROWNUM <= NGreen ORDER BY ORDER_ID ASC);
I would follow this with a second update statement to set the remaining records with "Yellow".
Thanks for your help!
I've tried something like this:
UPDATE TABLE SET COLOR = 'Green' WHERE ORDER_ID = (SELECT ORDER_ID FROM TABLE WHERE STATUS = 'Open' AND ROWNUM <= NGreen ORDER BY ORDER_ID ASC);
I would follow this with a second update statement to set the remaining records with "Yellow".
Thanks for your help!
Comment