Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comparing two identical tables and get matches

Author  Topic 

MalkyTheKid
Starting Member

1 Post

Posted - 2012-02-22 : 22:09:19
Good day to all,
My name is Malky, and I'm relatively new to the world of sql server scripting.I hope we could all be good friends

I have a question, is it possible to compare two identical tables and get matching records only? for example;
TableA TableB
Field1 Field2 Field1 Field2
1 A 1 A
2 A 2 B
3 B 3 B

What if in these two tables, I only wanted to output matching records? (I.E. my query should only return 1A and 3B)

Any help would be dearly appreciated. thank you very much

WingChunSQLGuy
Starting Member

1 Post

Posted - 2012-02-22 : 22:55:46
Do a Google search for EXCEPT and INTERSECT operators. I think this might help.

Salamat.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-22 : 23:19:31
[code]
select *
from tablea a inner join tableb b
on a.field1 = b.field1
and a.field2 = b.field2
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -