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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:00:04+00:00 2026-06-04T03:00:04+00:00

I have two tables (Table1 and Table2) with the same primary keys, lets say

  • 0

I have two tables (Table1 and Table2) with the same primary keys, lets say Key1 and Key2. What I need to do is seperate the records in Table1 into two groups, the duplicates (records found in Table2) and the non-duplicates. I know I could use the below, but that seems bloated and repetetive. Is there a trimmer way to do this, possibly with a single call?

SELECT Key1, Key2 FROM Table1 WHERE Key1 IN (SELECT Key1 FROM Table2) AND Key2 IN (SELECT Key2 FROM Table2);
SELECT Key1, Key2 FROM Table1 WHERE Key1 NOT IN (SELECT Key1 FROM Table2) AND Key2 NOT IN (SELECT Key2 FROM Table2);

;

This call is being made from a C# ASP.NET codebehind page.

  • 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-04T03:00:06+00:00Added an answer on June 4, 2026 at 3:00 am

    This query does a left outer join to ensure all records from table1 are returned. It joins on Table2, and if there are no matches, than any columns in Table2 will be NULL for that row. This behavior is used in a CASE statement to set a flag telling where the Table1 row exists in Table2 or not:

    select t1.*,
        case when t2.Key1 is null then 'false' else 'true' end as IsDuplicate
    from Table1 t1
    left outer join Table2 t2 on t1.Key1 = t2.Key1
        and t1.Key2 = t2.Key2
    

    You can then filter in your application based on the IsDuplicate column.

    • 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 the exact same columns. Both have primary identity keys
If two tables have foreign keys to the same primary key of another table,
I have a table with two primary keys,how can i map the same in
I have two tables with exactly the same fields. Table A contains 7160 records
How should I do if I have two tables and their primary keys have
How can I merge two MySQL tables that have the same structure? The primary
I have two tables with same structure **t1** +------+------+ | code | vid |
I have two tables with the same structure: id name 1 Merry 2 Mike
i have two data tables with the same structure the first one has one
I have two tables, A and B, that have the same structure (about 30+

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.