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

  • Home
  • SEARCH
  • 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 1022609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:29:30+00:00 2026-05-16T11:29:30+00:00

i have a Dimension Table like this : my_Table pk1 Primary key pk2 Primary

  • 0

i have a Dimension Table like this :

my_Table

pk1  Primary key
pk2  Primary key
pk3  Primary key
col1  
col2  
col3  
...

and using a procedure to fill this table with the MERGE INTO statement :

MERGE INTO  my_Table dest
USING 
  ( SELECT <columns>
      FROM <tables>
     WHERE <conditions> ) src
ON 
  (dest.pk1 = src.pk1 AND dest.pk2 = src.pk2 AND pk3 = src.pk3)
WHEN     MATCHED THEN UPDATE SET dest.col1 = src.col1 ,
                                 dest.col2 = src.col2 ,
                                 dest.col3 = src.col3
WHEN NOT MATCHED THEN INSERT (pk1, pk2, pk3, col1, col2, col3) 
                      VALUES (src.pk1, src.pk2, src.pk3, src.col1, src.col2, src.col3);

my problem is that the query ‘src‘ returns some rows with same Primary keys, but they are no duplicated rows, example

 | pk1 | pk2 | pk3 |  col1   | col2       | col3  |
 --------------------------------------------------
 | 100 | abc | x99 | 6000,00 | 01/01/2010 | 50,00 | 
 | 100 | abc | x99 | 0,00    | 01/01/2010 | 30,00 |
 | 110 | rty | b50 | 345,00  | 08/10/2009 | 10,00 |
 | 120 | xyz | y91 | 1200,00 | 13/02/2009 | 12,50 |
 | 120 | xyz | y91 | 1200,00 | 13/02/2009 |  0,00 |
 | 120 | xyz | y91 | 1200,00 | 13/02/2009 |  0,00 |
 | 120 | xyz | y91 | 1200,00 | 13/02/2009 |  0,00 |

So, when i call my procedure it returns the unique constraint violated error.

what could be the solution of this problem? im not the writer of the query src by the way …

if i need to modify src i should have for the pk (100,abc,x99) :

| pk1 | pk2 | pk3 |  col1   | col2       | col3  |   
 --------------------------------------------------    
| 100 | abc | x99 | 6000,00 | 01/01/2010 | 80,00 | 

and for the pk (120,xyz,y91) i would have :

| pk1 | pk2 | pk3 |  col1   | col2       | col3  |  
 --------------------------------------------------    
| 120 | xyz | y91 | 1200,00 | 13/02/2009 | 12,50 |

Thanks in advance for any suggestion.

  • 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-16T11:29:31+00:00Added an answer on May 16, 2026 at 11:29 am

    It’s obvious that something has to be done with src to make it return unique primary keys. If you don’t care too much about the quality of the data in your table, you could use aggregation and change it e.g. to

     select pk1, pk2, pk3, max(col1), max(col2), sum(col3)
       from ...
       where ...
       group by pk1, pk2, pk3
    

    But chances are you need more sophisticated processing to make any sense of that stuff.

    EDIT: changed first sum to max, to reflect the edit in the question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.