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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:54:50+00:00 2026-06-14T19:54:50+00:00

I have two tables A and B (with the same schema), and I want

  • 0

I have two tables A and B (with the same schema), and I want to merge them by inserting all entries from A into B. If table B already has data associated with a key from A, I want to silently drop those data.

The problem is that table B has a unique key index that consists of three columns, so I can’t just say “WHERE A.key <> B.key“.

I can’t seem to formulate an SQL statement along the lines of:

INSERT INTO B 
VALUES ((SELECT * FROM A WHERE ... NOT IN ...))

Is there a way to INSERT those rows from A into B where the corresponding three-column-key doesn’t exist in B yet?

  • 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-14T19:54:52+00:00Added an answer on June 14, 2026 at 7:54 pm
    INSERT INTO B 
    (Col1, Col2, Col3, ColN)
    SELECT
    A.Col1, A.Col2, A.Col3, COlN
    FROM A
    LEFT JOIN B
    ON A.COL1 = B.Col1
    AND A.COL2 = B.Col2
    AND A.COL3 = B.Col3
    WHERE B.Col1 IS NULL
    

    Essentially Join the 2 tables with a left join, and insert all from A where B is null (No corresponding value in B table for a Join on the 3 Key columns)

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

Sidebar

Related Questions

I have two tables with exactly the same fields. Table A contains 7160 records
I have two classes generated by LINQ2SQL both from the same table so they
I have two tables with the exact same schema in SQL Server 2008 Standard
I have two tables with same schema , and primary key as noc for
I have two tables defined for actual and expected with exactly the same schema.
I have two tables both have same schema, one will have previous day records
I'm working on mysql and have two tables with the same schema: preTrial |id|accusedId|articleid|
I have two tables (with the same schema) Table1 id title D0 D1 D2
I have two tables auth_user and temp These are their schema: CREATE TABLE auth_user
i have two database A,B with same number of tables and schema in sql

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.