I am trying to write a write and the logic I am looking for is basically. If any User IDs from Table 1 do not exist in Table 2 show those in the results. So I did:
SELECT
UserColder.ContactName,
UserColder.Phone,
UserColder.Email,
UserColder.Website,
Country.Name,
UserColderZIP.[ZIP Code],
UserColderZIP.[State Abbreviation]
FROM
dbo.UserColder
LEFT OUTER JOIN dbo.CountryUser
ON UserColder.ID = CountryUser.[User ID]
INNER JOIN dbo.Country
ON CountryUser.[Foreign ID] = Country.ID
LEFT OUTER JOIN dbo.UserColderZIP
ON UserColder.ID = UserColderZIP.UserColder
WHERE
UserColder.ID NOT IN (CountryUser.[User ID])
It returns data without the Where But with the Where I am trying to get it to show all the results where the Id from UserColder don’t have any records in CountryUser. Right now it is returning no results and I know ID 2 doesn’t exist in there. Any idea what I am doing wrong?
Thanks!
Since you have a
LEFT OUTER JOIN, to get records fromUserColderthat don’t exist inCountryUser, check forNULL. The joined rows which have no corresponding value will returnNULL.