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
 Merging tables

Author  Topic 

rmg1
Constraint Violating Yak Guru

256 Posts

Posted - 2010-10-07 : 06:18:12
Hi all

I've got two tables with almost identical data in them.
I need to check for a Unique ID number made up of Employee ID, first name and surname (all concatenated) where it appears in one table but not the other.
At the moment, the query I have is checking record by record in both gables and giving me far too many results.

I want the query to check if the Unique ID in table 1 appears in anywhere in table 2 and if it does ignore it. I only want to get back the Unique IDs where they don't appear in both tables.

Hope this makes sense and any help greatly appreciated.

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 06:35:23
quote:
I want the query to check if the Unique ID in table 1 appears in anywhere in table 2 and if it does ignore it. I only want to get back the Unique IDs where they don't appear in both tables.



Both the statements dont seem to relate.Can you post some sample data & expected o/p?

PBUH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-08 : 06:13:45
select t1.* from table1 as t1 where not exists(select * from table2 where EmployeeID=t1.EmployeeID and firstname =t1.firstname and surname =t1.surname )

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -