NEGATION JOIN IN SQL SERVER 2005


Hi All,
 
Today, I again come up with a very interesting problem with a very simple solution.
 
Scanerio:
I have two tables, let me call the first table "A" and second table be "B". Both tables have a common column called EMAIL on which we can apply a join.
 
Requirement:
I want to select all those records which do not match Email Criteria in both tables, if this goes over your heads, let me tell rephrase this for you. It will be to SELECT ALL THOSE RECORDS WHERE A.EMAIL IS NOT EQUAL TO B.EMAIL
 
Solution:
After careful analysis, here’s what comes in my mind and this might save your many mintues. Here’s the query…
 
SELECT A.Email FROM A WHERE A.Email NOT IN (SELECT B.Email FROM B)
 
I named it NEGATION JOIN :) Does this make sense for you people. Please do let me know if you figure out somthing is missing or wrong.
 
Happy coding!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: