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
 SQL Server Development (2000)
 Compare Data In Two Different Tables

Author  Topic 

REL
Starting Member

2 Posts

Posted - 2005-04-27 : 11:09:37
Hello SQL Team, I need your help.
I’m using SQL 2000 with the latest service pack. I have two tables within the same database. Both tables are for computer inventory. The primary key in both is the serial number of the item. One table is the computer inventory kept by us and the other table is the master inventory. I want to compare the two tables and display by query all the items that don’t match up in both tables. These items will be the missing items. It sounds simple but for some reason I can’t get my brain to put out the code. Maybe I’m stressed about the inventory. Thanks


Rogastan Ellis

mr_mist
Grunnio

1870 Posts

Posted - 2005-04-27 : 11:16:01
What do you mean by "the items that don’t match up in both tables"?

Do you mean just the keys? The whole table?

SELECT * from yourmaintable LEFT OUTER JOIN yourothertable ON key = key WHERE yourothertable.key IS NULL

Would show you ones where they don't exist. Otherwise look at joining on all the fields for a direct comparison, or using a product like Red Gate Data compare.

-------
Moo. :)
Go to Top of Page

pentiumsingh
Starting Member

9 Posts

Posted - 2005-04-27 : 11:28:24
select * from [masterinventory] where serial not in (select serial from [computerinventory])
or by the item name
select * from [masterinventory] where item not in (select item from [computerinventory])

Pentiumsingh
Go to Top of Page
   

- Advertisement -