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.
Author |
Topic |
mirirom
Starting Member
7 Posts |
Posted - 2009-07-27 : 12:01:19
|
hi, there's probably an obvious answer to this, but for the life of me a group of us here at work can't seem to figure out this problem using a "where in" condition. we've two tables containing a zip-code column. both columns are defined with the EXACT same datatype (int, nullable, non-computed, etc). we know that tblA has more distinct zip-codes than tblB (i.e. select distinct zipCode from tblA returns more rows than select distinct zipCode from tblB), so what's the problem with the following?select distinct zipCode from tblAwhere tblA.zipCode not in (select distinct zipCode from tblB) running this returns 0 rowshowever, this works just fine.select distinct a1.zipCode from tblA a1where a1.zipCode not in (select distinct a2.zipCode from tblA a2 inner join tblB b2 on a2.zipCode = b2.zipCode) any thoughts are greatly appreciated... |
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2009-07-27 : 12:25:55
|
tblB must contain a NULL zipCode.http://www.simple-talk.com/sql/sql-training/sql-and-the-snare-of-three-valued-logic/ |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-27 : 12:26:39
|
[code]SELECT distinct a.zipCodeFROM tableA aLEFT JOIN tableB bOn a.zipcode = b.zipcodeWHERE b.zipCode is NULL[/code] |
|
|
mirirom
Starting Member
7 Posts |
Posted - 2009-07-27 : 14:46:16
|
"nulls" it was. thanks guys, much appreciated. |
|
|
|
|
|