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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:51:35+00:00 2026-05-18T10:51:35+00:00

I need to synchronize two tables. Let’s assume that the tables contain following columns:

  • 0

I need to synchronize two tables. Let’s assume that the tables contain following columns:

Table1: A, B, C, D  
Table2: A, B, C, E

I need to find such rows in Table1 that there isn’t entry with corresponding (A, B, C) values in Table2, then calculate E as F(D) and update Table2.

If I need to match e.g. only A, I would write the following query:

SELECT * FROM Table1 WHERE A NOT IN (SELECT A FROM Table2)

Multi-column analog seems to be too slow:

SELECT * FROM Table1 WHERE A NOT IN (SELECT A FROM Table2)
                       AND B NOT IN (SELECT B FROM Table2)
                       AND C NOT IN (SELECT C FROM Table2)

What is the best way to write such query?

  • 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-18T10:51:36+00:00Added an answer on May 18, 2026 at 10:51 am

    If (a,b,c) are NOT NULL in both tables, both NOT IN and NOT EXISTS will most likely (on the verisons I have tried) generate the same execution plan.

    If (a,b,c) are declared as nullable, but you know that the columns are in fact not null, you can trick the optimizer into doing the hash anti join anyway by adding “AND a is not null AND b is not null AND c is not null” to your query. (You may also have to add a /*+ HASH_AJ */ hint in the sub query.)

    Also, the following queries are NOT identical:

     from table1
    where (a,b,c) not in (select a,b,c from table2)
    
     from table1
    where a not in(select a from table2)
      and b not in(select b from table2)
      and c not in(select c from table2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a software that let me compare and synchronize two database on two
I just realized that I need to synchronize a significant amount of data collection
I need to have ALWAYS a background service that will synchronize my Android application
Need help with a query that I wrote: I have three tables Company id
I need to synchronize a path animation on two different layers (one is used
Let's say I have two Databases like so : DatabaseA create table Table1 (
I need to synchronize two sql server 2005 instances between intranet and extranet (through
I need to synchronize two databases. Those databases stores same semantic objects but physically
I need to synchronize time between two or more android devices. But I don't
I have two tables (let's call them A and B) with same structure and

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.