I have one table, e.g. pricerules, that have stored special prices by article for customers. Now I want to sync the pricerules, based on an other user. Suppose I have this as dataset:
+---------------------------+
| user_id | prod_id | price |
+---------+---------+-------+
| 10 | 1 | 1 |
| 10 | 2 | 5 |
| 10 | 3 | 7 |
| 20 | 2 | 5 |
| 30 | 2 | 5 |
| 30 | 3 | 7 |
+---------+---------+-------+
Now I would like to update/insert the prices for several other users, based upon the prices of user 10. I already wrote the delete and update query, but I’m stuck with the insert query to insert the new rules that the other users don’t have yet.
So effectively this would do the following inserts:
INSERT INTO pricerules
(user_id, prod_id, price)
VALUES
(20, 1, 1),
(20, 3, 7),
(30, 1, 1);
Is there a way to do this in one query? I have been looking for MINUS to select the records that are not present for user 20, but I would have to execute a query for each user.
I thought maybe I could use MERGE.
I am using Oracle 10.1 ..
You were right. Merge is the way to go. Please try the following.