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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:23:24+00:00 2026-05-25T11:23:24+00:00

I have a scenario where I need to join two SQL tables and am

  • 0

I have a scenario where I need to join two SQL tables and am struggling with how to do it.
Let’s say in table A I have this:

ColA  ColB   ColC   ColD
45     55     17     45
45     55     17     47
45     55     17     49
45     55     17     51

And in Table B I have this:

ColA  ColB   ColC   ColE
45     55     17     55
45     55     17     56
45     55     17     57
45     55     17     58

I need to create a table that looks like this – note only the 4 rows, not the 16 that the inner join I was using produces.

ColA  ColB   ColC   ColD   ColE
45     55     17     45     55
45     55     17     47     56
45     55     17     49     57
45     55     17     51     58

I’m pretty much out of ideas. Both tables will always have the same number of rows. Is there a way to do this using joins, or should I iterate through the table A (ie get the row number) and get the matching row number in Table B?

Any thoughts would be greatly appreciated.

  • 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-25T11:23:24+00:00Added an answer on May 25, 2026 at 11:23 am

    Assuming at least SQL Server 2005

    WITH T1
         AS (SELECT *,
                    ROW_NUMBER() OVER (PARTITION BY ColA, ColB, ColC ORDER BY ColD)
                    RN
             FROM   TableA),
         T2
         AS (SELECT *,
                    ROW_NUMBER() OVER (PARTITION BY ColA, ColB, ColC ORDER BY ColE)
                    RN
             FROM   TableB)
    SELECT T1.ColA,
           T1.ColB,
           T1.ColC,
           T1.ColD,
           T2.ColE
    FROM   T1
           JOIN T2
             ON T1.ColA = T2.ColA
                AND T1.ColB = T2.ColB
                AND T1.ColC = T2.ColC
                AND T1.RN = T2.RN  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How are this two concepts work together ? I have a scenario city table
I have this scenario where I need data integrity in the physical database. For
Let's says I have a set of tables that match the following scenario: Crates
I have two MySQL tables: house and features . This is for a real
I have the following scenario.I need to recommend artists to users. How should this
Very simplified, I have two tables Source and Target. declare @Source table (SourceID int
In my scenario I have the following 2 tables: Table 1: tdc_doc_field_def Column 1:
My scenario is this. i have a telephone table that needs to be updated
I have scenario like, I need to add my join in conditional e.g. When
I've got a scenario where I need to do a join across three tables.

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.