SQL - Find which values in List is not in table

I have been provided a list of approx 1000 values.  I need to perform an update based on these ID's.  I performed a selection on this list.  As an example

Select * from myTable where id IN (1, 2, 3, 4, 5, .... )

The results returned 995 out of the 1000 id's that were provided.  Is there a way to write a script to determine which of the 5 id's that were provided are not in the list?
LVL 2
CipherISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Create a new table (ids) with a single column (id) and insert your list into it.

>Is there a way to write a script to determine which of the 5 id's that were provided are not in the list?
SELECT ids.ID
FROM ids
   -- LEFT JOIN means return all rows from the list ids...
   LEFT JOIN myTable mt ON mt.id = ids.id
-- And then filter only on the ones not in MyTable
WHERE mt.id IS NULL

Open in new window


<edited after original post>
0
David L. HansenProgrammer AnalystCommented:
SELECT * FROM myTable WHERE NOT IN (1,2,3,4,5,...)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Commented:
With the list in a table, idlist -
select id from idlist except select id from mytable;
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

CipherISAuthor Commented:
Sorry, I should clarify.  There are 100,000 records in the table.  I was provided a list of 1000 to search for but only 995 returned and I want to know which 5 in the list did not return.
0
CipherISAuthor Commented:
What I did was used the list used your approach.  I created two internal tables.  One to select from the table creating an internal table #t1.  Then I created an internal table #t2 from the list that I was provided to search with.  I used your example to search for the nulls.  There were none.  Found out that there were duplicates so I had to write another sql statement to find the duplicate.  Thank You.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>I was provided a list of 1000 to search for but only 995 returned and I want to know which 5 in the list did not return.
Yep, did you try the first comment in this question?
0
awking00Commented:
That's exactly what the set operator would do. If you create a one table for the list, you don't need another.
select id from list except select id from mytable will produce any ids in the list not in the table and will do so regardless of duplicates.
0
David L. HansenProgrammer AnalystCommented:
Glad to help CipherIS.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.