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
 How to write a query for this

Author  Topic 

Benny_57
Starting Member

2 Posts

Posted - 2013-07-23 : 06:30:57
Hi!

I have 2 tables.
Both tables containes a field called itemno
These 2 tables should containe the same amount of rows, but are not.
Tabel 1 containes 791 and tabel 2 contains 736.
How do i write a query to get the answer witch itemno missing in table 2?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-23 : 06:33:33
There are a few different ways to write the query. One way is as follows:
SELECT itemno from Table1 EXCEPT SELECT itemno from Table2;
SELECT itemno from Table2 EXCEPT SELECT itemno from Table1;
The first gives you a list of itemno's in table1 that are not in table2. Second one gives the opposite.

Go to Top of Page

Benny_57
Starting Member

2 Posts

Posted - 2013-07-23 : 06:37:52
Thank's for the quick replay James K
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-23 : 07:32:02
just FYI
NOT EXISTS,LEFT JOIN, NOT IN can also be used for same scenario

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -