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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:37:21+00:00 2026-06-18T12:37:21+00:00

How can we copy data from one table into another table which doesn’t exist

  • 0

How can we copy data from one table into another table which doesn’t exist in the first one. In table one of the column is primary key.

INSERT INTO table SELECT * FROM db2.table; 
ERROR 1062 (23000): Duplicate entry '100001' for key 'id_UNIQUE'
  • 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-06-18T12:37:22+00:00Added an answer on June 18, 2026 at 12:37 pm

    You can use the predicate NOT IN to do so like this:

    INSERT INTO table1 
    SELECT * 
    FROM db2.table2 
    WHERE table1ReferenceID NOT IN(SELECT id_UNIQUE FROM table1);
    

    This will checks whether this table1ReferenceID found in the first table or nor. Therefore, the SELECT clause will select all the rows from the second tables except those that is already presented in the first table table1.

    Note that: the column table1ReferenceID is the reference of the id_UNIQUE in the second table.

    Other alternatives for this, is to LEFT JOIN as suggested by @HamletHakobyan‘s answer and NOT EXISTS.

    • See it in action
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I copy data from one table (table A) to another (table B)
How can we copy one datacolumn with data from one datatable to another datatable
I need to copy some data from one table to another in Oracle, while
I'm writing a stored procedure to copy data from one user's table to another
I want to copy data from one database which has table named domains to
I need to copy a set of data from one table to another that
I want to copy data from one table to another in MySQL. Table 1
I want to copy data from two columns in a 'table1' to another table
I'm trying to take data from one column, MyTable.SSN , and copy it to
I'm using SqlBulkCopy to bulk insert some records from one table into another table.

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.