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)
 Checking table comparision using SQL

Author  Topic 

satya068
Posting Yak Master

233 Posts

Posted - 2010-05-20 : 09:39:36
Hi..

i am comparing two tables T1 aand T2,i am supposed to get same no_of records in both tables.
but in T1 50 and T2 57
now i want to find in which column got exxcess records in table T2

i checked the key_code column for any duplicates using the below sql there are no duplicates in the key_code column.

select * from
(
select KEY_CODE, count(*) as cnt
from Employee_id
group by KEY_CODE
) inq
where cnt > 1

is there any other way to find that records in T2?

would you guys have any idea about this please?

thanx in advance.

Satya

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-05-20 : 09:59:11
If both tables have exact same key_codes, below query compares both tables to find extra records in t2:


select t2.* from Employee_id2 t2 left join Employee_id1 t1
on t2.key_code = t1.key_code
where t1.key_code is null


Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

satya068
Posting Yak Master

233 Posts

Posted - 2010-05-20 : 10:12:03
Thanx harsha.

Satya
Go to Top of Page
   

- Advertisement -