Select recoreds that do not exist in a table

I have 2 tables   A and B.  I poplutae B with some recorrds that exist in A.
I want to grab all the records in A that do not exist in B

i am trying this but does not work.

select  id  from A where id not in(select id from B)
angireddyAsked:
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.

dportasCommented:
SELECT id FROM A
EXCEPT
SELECT id FROM B;
0
pollock_dCommented:
SELECT ID FROM A WHERE EXISTS(SELECT * FROM B)
0
vs1784Commented:
I dont find any reason for below code to not work

SELECT ID FROM Table1 WHERE ID NOT IN(SELECT ID FROM Table2)

Make sure both ID columns are of same datatypes.

Thanks
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

dportasCommented:
Always beware of null. The most likely explanation why your query did not work as expected is that you have nulls in table B. Try modifying it as follows:

SELECT  id  FROM A WHERE id NOT IN (SELECT id FROM B WHERE id IS NOT NULL);
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
vs1784Commented:
I agree with dportas, it should work if you check NULL.
0
pollock_dCommented:
SELECT ID FROM A WHERE NOT EXISTS(SELECT * FROM B)
0
dportasCommented:
pollock_d: You posted that same answer twice. But you were wrong both times! :) Your query isn't correlated so it won't give the answer that the OP asked for.
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 2005

From novice to tech pro — start learning today.