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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Compare two Tables

Author  Topic 

mvtechnet
Starting Member

1 Post

Posted - 2011-07-29 : 09:16:39
(Hope this is right forum)
I have two tables that I need to compare.

the criteria is to compare item and revision.

Check to see if item from table1 exist in table2.
If item exist then check to see if the revision value matches.

I want to see non existent items and revisions that do not match.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-29 : 09:50:04
You could use the EXCEPT keyword.

select Item,Revision from Table1
EXCEPT
select Item,Revision from Table2
INTERSECT keyword instead of the EXCEPT keyword would give you the intersection (i.e., Item and Revision that exist in both tables).
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-29 : 11:52:13
other ways of achieving same requirement are by using LEFT JOIN and NOT EXISTS

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -