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 2000 Forums
 Transact-SQL (2000)
 non matching data in tables

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2005-10-03 : 09:08:20
Hi, I have 2 tables All and Selected.
the All table has 2000 rows, firstname, surname, address.
Selected has 200 rows, firstname, surname, address.

How can I find out which rows exist in Selected but not in All.

and also vice versa... which rows exist in All but not selected...

thank you ..

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2005-10-03 : 09:11:55
select a.* from dbo.all a where not exists (select b.* from b.selected b where a.firstname = b.firstname and a.surname = b.surname and a.address = b.address)


and then swop the two tables around in the query for vice versa


Duane.
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2005-10-03 : 09:13:39
that was quick !
thank you.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-03 : 09:14:27
1

Select * from Selected S where not exists
(Select * from All where firstName=S.firstName and surname=S.surname and address=S.address)

2


Select * from All A where not exists
(Select * from Selected where firstName=A.firstName and surname=A.surname and address=A.address)


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-03 : 09:15:25
ditch, you are so fast

Madhivanan

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

- Advertisement -