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 6611637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:59:43+00:00 2026-05-25T19:59:43+00:00

I have two tables, TABLESource is where will i get the records to be

  • 0

I have two tables, TABLESource is where will i get the records to be inserted in TABLEDest,

now TABLESource can contain duplicate fields:

id  code    name
2   09  abc
3   10  uu
2   09  def
3   10  rr
2   09  gh

and i have to insert first all the unique records in the TABLEDest, the id+code is primary key (unique)

id  code    name
2   09  abc
3   10  uu

now, in the end, if the TABLESource found duplicate id and name, it must update the TABLEDest with the latest records found in the TABLESource with the same primary key (id_name)

id  code    name
2   09  gh
3   10  rr

I have no clue how to do that. Please help me. THanks 🙂

  • 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-25T19:59:44+00:00Added an answer on May 25, 2026 at 7:59 pm

    I would suggest iterating through your source table and for each row in the source:

    Psudo Code:
    //Get all source rows
    query = 'SELECT * FROM TABLEsource'
    rows = database.get(query)
    
    //Iterate through all source rows
    for each rows as row{
        //Search dest table for a match    
        checkQuery = 'SELECT * FROM TABLEDest WHERE id = '+row.id
        check = database.get(checkQuery)
    
        //If we do get a match
        if(check.rows > 0){
    
           //Update the relevant row
           query = 'UPDATE TABLEDest SET name = '+row.name+' WHERE id = '+check.id
           database.query(query)
    
        }else{
    
           //Otherwise, append a new row to the dest table
           query = 'INSERT INTO TABLEDest(id, code, name) '
                  +'VALUES('+row.id+'. '+row.code+', '+row.name+')'
           database.query(query)
    
        }
    }
    

    This is psudo code, so directly copying and pasting won’t work, but it should be enough for you to use your favorite flavor of language to make it happen.

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

Sidebar

Related Questions

I have two tables, both with start time and end time fields. I need
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables Master Detail In the Master & Detail table I get
Have two sets of data (two tables) for patient records, one 1999-2003, the other
I have two tables with a foreign key constraint how can I delete rows
I have two tables like Parent-Child. In Parent table, there are 7211 records. In
I have two tables,Forms and Attributes. I'm tring to retrieve the last inserted id
I have two tables, users and hra. A user can only have one record
I have two tables: hotels and hotel_rooms I'm trying to get a table with
I have two tables that are joined together. A has many B Normally you

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.