|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Select Query (not in question) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|