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)
 How to Compare two tables each columns and find th

Author  Topic 

libraguy88
Starting Member

1 Post

Posted - 2009-08-26 : 17:00:25
Hii ppl,

I have an issue, i need to compare 2 tables and compare their columns for data,both having the same data type,
Table 1
Name SSN EmpID Plan
Table 2
Name SSN EmpID Plan

no PK,FK relation between the tables.how to compare them..

plz help.. it is too urgent

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-08-27 : 10:56:27
so what should be result? non repeting values from both table? or values which are in both?
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-27 : 13:40:43
Here is one way to show all differences:

select max(src) as src, [Name], SSN, EmpID, [Plan]
from (select src = 'table1', [Name], SSN, EmpID, [Plan] from table1
union all
select src = 'table2', [Name], SSN, EmpID, [Plan] from table2
) d
group by [Name], SSN, EmpID, [Plan]
having count(*) = 1


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -