| Update a column in table only if a condition is met for number of values for a field in other table [message #638760] |
Fri, 19 June 2015 19:53  |
 |
suhaas
Messages: 5 Registered: June 2015
|
Junior Member |
|
|
I am trying to figure out how to achieve the following (This is simplified version that ignores non relevant columns)
I have table "Item" with columns
item_id business_key
I have another table "Order" with columns
order_id business_key item_id
Here is the problem statement.
For a given item_id in Item table, find orders that have only one unique business_key associated with it in Order table. Mind you, unique business_key could mean one or more rows for the unique combination of business_key and item_id. In this case, I need to take business_key derived from Order table and update the Item table with that value.
So if the Order table has values
Scenario I
Order Table order_id business_key item_id 1 apple 12 2 apple 12
Then I need to update business_key in Item table with "apple"
Scenario II
However, Order table has values order_id business_key item_id 1 apple 12 2 orange 12
Nothing needs to be done. business_key in Item table needs no update (it is null by default)
What is the best approach. I have considered subqueries, Oracle Merge but I have not come up with a solution. Is PL/SQL the only answer?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|