Ran it in my query browser. I was am getting same results for both. But still need a confirmation.
SELECT
cs.RSCode
, CustomerName
, em.EmailId
FROM
Customer_STN cs
JOIN EmployeeMaster em ON cs.RSCode = em.UserName
LEFT OUTER JOIN Confirmed_Attendance ca ON cs.RSCode = ca.rsCode
WHERE
isConfirmed=1
AND
dateOfConfirmation = '2012-08-25'
Second query:
SELECT
cs.RSCode
, CustomerName
, em.EmailId
FROM
Customer_STN cs
JOIN
EmployeeMaster em ON cs.RSCode = em.UserName
WHERE
RSCode NOT IN (
SELECT
rsCode
FROM
Confirmed_Attendance
WHERE
dateOfConfirmation = '2012-08-25'
AND
isConfirmed = 1
)
EDIT: Added the WHERE
part as Rob noticed. Not so similar any more.
WHERE
you have added turns the outer join back into an inner join. You would need the rewrite in @ypercube's answer with the filter in theON
(and a filter in the where clause to bring back only null extended (unmatched) rows). Table definitions (including column nullability) would definitely be useful here as well.WHERE
you have added makes it really hard for the 2 queries to produce the same results. Unless thatNOT IN
isIN
in the 2nd query. Which would change the question vastly.CustomerName
is pretty obvious, how do I figure out what tableisConfirmed
anddateOfConfirmation
come from? This can be very important to identify quickly especially since it really does matter for outer joins.