I have the following code which, when run separately, produces the results I expect but when run collectively returns nothing:
SELECT SurveyUID FROM tbSurvey AS tbS
WHERE NOT EXISTS
(SELECT tbS.SurveyUID
FROM tbSurvey AS tbS INNER JOIN
tbSurveyElementCategory AS tbSEC ON tbS.SurveyUID = tbSEC.SurveyUID INNER JOIN
tbElementCategory AS tbEC ON tbSEC.ElementCategoryID = tbEC.ElementCategoryID
WHERE (tbEC.ElementCategoryID = 75))
The first line returns 185 records and the sub-query returns 20 records as a sub-set of the first query. I am trying to return the 165 records that don't appear in the sub-query. Thanks
You forgot put tbS.SurveyUID = tbS1.SurveyUID condition
Try this: