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 question is related to
sql
sql-server
tsql
notin
SELECT d1.Short_Code
FROM domain1 d1
LEFT JOIN domain2 d2
ON d1.Short_Code = d2.Short_Code
WHERE d2.Short_Code IS NULL
I would opt for NOT EXISTS
in this case.
SELECT D1.ShortCode
FROM Domain1 D1
WHERE NOT EXISTS
(SELECT 'X'
FROM Domain2 D2
WHERE D2.ShortCode = D1.ShortCode
)
Source: Stackoverflow.com