Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 1Name SSN EmpID PlanTable 2Name SSN EmpID Planno 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?
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 ) dgroup by [Name], SSN, EmpID, [Plan]having count(*) = 1