Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:13:36+00:00 2026-05-31T18:13:36+00:00

I have one table, e.g. pricerules, that have stored special prices by article for

  • 0

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 ..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:13:38+00:00Added an answer on May 31, 2026 at 6:13 pm

    You were right. Merge is the way to go. Please try the following.

    merge into pricerules p
    using ( select t1.user_id, t2.prod_id, t2.price
       from 
       (select distinct user_id
       from pricerules
       where user_id <> 10) t1,
       (select distinct prod_id, price
       from pricerules
       where user_id = 10) t2
       ) t
    on (p.user_id = t.user_id
       and p.prod_id = t.prod_id
       and p.price = t.price)
    when not matched then 
       insert (user_id, prod_id, price) values (t.user_id, t.prod_id, t.price) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have one table called REVIEWS This table has Reviews that customers
I have one table with 2 columns that i essentially want to split into
I have one table ( Stock_ID, Stock_Name ). I want to write a stored
i have one table sql server like below , from that table i want
I have one table that contain lots of records and I want to update
I have one table that saves comments for a varied set of content types.
I have one table orders with a foreing key ProductID. I want to show
I have one table having ID and other attributes. How can I get list
I have one table that has sales records and another table that has additional
I love NHibernate's ability to have one table to store multiple types based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.