• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

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)
0
angireddy
Asked:
angireddy
  • 3
  • 2
  • 2
1 Solution
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now