Could some one please provide how to write following sql query using joins. I do not want use not in as well as if possible I would like to replace where condition as well.
SELECT d1.Short_Code
FROM domain1 d1
WHERE d1.Short_Code NOT IN (
SELECT d2.Short_Code
FROM Domain2 d2
)
I am using SQL Server 2008
This article:
may be if interest to you.
In a couple of words, this query:
will work but it is less efficient than a
NOT NULL
(orNOT EXISTS
) construct.You can also use this:
This is using neither
NOT IN
norWHERE
(and even no joins!), but this will remove all duplicates ondomain1.short_code
if any.I would opt for
NOT EXISTS
in this case.