Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Not In" SELECT query not working 1

Status
Not open for further replies.

DoubleWeb

Programmer
Mar 20, 2006
9
US
Hello all,
I had this query working for 2 years with no problem and now, all of a sudden it can't find the records anylonger.

The Table "WWTester" has 17 records. I have a query that reads:

SELECT WWTESTER.homephone, WWTESTER.firstname, WWTESTER.lastname
FROM WWTESTER
WHERE (((WWTESTER.homephone) In (SELECT Homephone FROM guesttrack_clean)));

The Table "guesttrack_clean" is another table used just to compare data. This query above retrieves me 5 records and the records are perfectly fine.

Now, I have another query that does the opposite, like that:

SELECT WWTESTER.homephone, WWTESTER.firstname, WWTESTER.lastname
FROM WWTESTER
WHERE (((WWTESTER.homephone) Not In (SELECT Homephone FROM guesttrack_clean)));

And thats where the problem is.. Its not giving me any records at all. Should give me 12 records Correct? Exactly the records not in the first query I listed above.

Any clues...
Thanks a lot!
DBWEB
 
Are the WWTESTER.homephone that are not showing up null by any chance?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
No Greg.. The homephone field can't be null on that table and I've already "manually" tested and found the records that are NOT in the guesttrack_clean table. I searched for homephone numbers that ARE in the WWTester table and NOT in the guesttrack_clean table..

Its weird that the IN (SELECT... query works and the NOT IN (SELECT... doesn't.
 
You may try either this:
SELECT WWTESTER.homephone, WWTESTER.firstname, WWTESTER.lastname
FROM WWTESTER
WHERE Not (WWTESTER.homephone In (SELECT Homephone FROM guesttrack_clean))
Or this:
SELECT WWTESTER.homephone, WWTESTER.firstname, WWTESTER.lastname
FROM WWTESTER LEFT JOIN guesttrack_clean ON WWTESTER.homephone = guesttrack_clean.Homephone
WHERE guesttrack_clean.Homephone Is Null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
Thanks Once again! The second option you gave me worked. BUt the first one did not.
Could you tell me why or what is wrong with my query that does not work?

I Appreciate it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top