Sql Check One List Against Another
I'd appreciate any pointers on how in SQL to check whether elements in one list also appear in another. List A = Live Customers in April List B = Live Customers in May How can I c
Solution 1:
Different ways to pull the results
SELECT customer
FROM ListA a
WHERENOTEXISTS (SELECT1FROM ListB b WHERE a.customer=b.customer)
OR
SELECT a.customer
FROM ListA a
LEFTJOIN ListB b ON a.customer=b.customer
WHERE b.customer isnullOR
SELECT customer
FROM ListA
exceptSELECT customer
FROM ListB
OR
SELECT customer
FROM ListA
WHERE customer NOTIN (SELECT customer FROM ListB )
Solution 2:
Try the not in clause
example
select *
from mytable
where id notin (select id from table2)
this will return results that are not in another table. quick and simple
Post a Comment for "Sql Check One List Against Another"