MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 10th, 2004, 04:08 PM
cmv131 cmv131 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 33 cmv131 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 41 m 24 sec
Reputation Power: 5
Select Query (not in question)

I am trying to select a column from table A where that value does not appear in table B. Here is what I am using
Code:
SELECT A from tableA
where A
not in (Select distinct B from tableB)


But it returns no results

However if I use
Code:
     SELECT A from tableA

I get 211 records


and I use
Code:
     Select distinct B from tableB

I get 105 records.

So in theory I should have 106 rows returned from my query. I am assuming it is something simple I am missing (hopefully), and that the experts here can find it faster than I can!

Thanks
Chris

Reply With Quote
  #2  
Old November 10th, 2004, 04:21 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
Don't you have it backwards?
Select distinct B from tableB
where B
not in (SELECT A from tableA)

Since you want it to look in the table with more records.

Reply With Quote
  #3  
Old November 11th, 2004, 09:40 AM
cmv131 cmv131 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 33 cmv131 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 41 m 24 sec
Reputation Power: 5
That gives me the same result.

I want to compare the table with more records, to one with fewer, and figure out the IDs that are in table A but not B.

Reply With Quote
  #4  
Old November 11th, 2004, 04:42 PM
cmv131 cmv131 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 33 cmv131 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 41 m 24 sec
Reputation Power: 5
I found the problem. I had a stray null value in table B.
Code:
SELECT A from tableA
where A
not in (Select distinct B from tableB where B is not null)


did the trick

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Select Query (not in question)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT