4

I have a list of 338 strings like the following:

013705
013707
013708
013709

How do I get all of those strings that do not exist in my table/column: tblclients.clientID?

I've tried the following:

SELECT clientID FROM tblclients WHERE clientID NOT IN (
000100,
000834,
001855,
etc...)

But that only returns values from my table that do not exist in my list of strings. I need the opposite: strings from my list, that do not exist in the table. I'm wondering if this is possible with SQL or if I need to use Excel in some way...?

FastTrack
  • 8,810
  • 14
  • 57
  • 78

2 Answers2

1

If the numbers that you are testing are in YourNumbers then you can run a query like this:

SELECT clientID 
FROM YourNumbers y
LEFT JOIN TblClients t ON y.clientID = t.clientID
WHERE clientID IS NULL
PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • The question states that the numbers are not in a table. – User15 Aug 10 '15 at 21:47
  • @User15 - I read it that OP wants to find numbers which are not in his main table. The numbers to compare have to be stored somewhere. My solution uses a temporary table for this purpose. – PM 77-1 Aug 10 '15 at 21:59
0

I have the same case here...

If the DB supports Common Table Expressions and there are not too many values to check:

create table reftable (
   pkey int not null primary key,
   name varchar(40)
);
insert into reftable values ( 101, 'aaaaa' );
insert into reftable values ( 103, 'bbbbbb' );

with checklist as
(
select 101 c1
 union
select 102 c1
 union
select 103 c1
 union
select 104 c1
)
select c1 from checklist
   where c1 not in (select pkey from reftable);

Still looking for a better solution...

Seb
  • 59
  • 9