SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to write a query for this
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 07/23/2013 :  06:30:57  Show Profile  Reply with Quote

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
Flowing Fount of Yak Knowledge

3858 Posts

Posted - 07/23/2013 :  06:33:33  Show Profile  Reply with Quote
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

Starting Member

2 Posts

Posted - 07/23/2013 :  06:37:52  Show Profile  Reply with Quote
Thank's for the quick replay James K
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 07/23/2013 :  07:32:02  Show Profile  Reply with Quote
just FYI
NOT EXISTS,LEFT JOIN, NOT IN can also be used for same scenario

SQL Server MVP

Edited by - visakh16 on 07/23/2013 07:34:21
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000