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.
Assuming at least SQL Server 2005