I tested your code, and it didn't give me customer numbers that I wasn't expecting. However, in your FROM clause, there is nothing relating table1 to table2. This gives you a cross-join (a.k.a. Cartesian Product) when you execute it. A corrected version of this would be:
select table1.customerNumber from table1
where table1.customerNumber not in (select table2.customerNumber from table2)
This gives a correct result.
An alternative method for doing this type of result retrieval uses a LEFT JOIN like so:
select table1.customerNumber
from table1
left join table2
on table1.customerNumber = table2.customerNumber
where table2.customerNumber is null
Depending on the size of the tables and the indices on each table, it could give you superior performance.
Hope this helps! Good luck!
BitBlt
Practically a Posting Shark
894 posts since Feb 2011
Reputation Points: 482
Solved Threads: 148
Skill Endorsements: 14
You simply need
Select customerNumber From Table1
Where customerNumber NOT IN (select customerNumber from table2)
You don't need to join or select from 2 tables in the main part of your query
simplypixie
Practically a Master Poster
642 posts since Oct 2010
Reputation Points: 157
Solved Threads: 118
Skill Endorsements: 5
Question Answered as of 1 Year Ago by
simplypixie
and
BitBlt