I am very much a beginner and I completely get what NOT IN does, but don't really get EXISTS or NOT EXISTS. Even more, I don't understand what this does:
SELECT TOP 1 1 FROM tblSomeTable What does this query actually do?
For reference, I have been working with something like this:
SELECT COUNT(E_ID) FROM tblEmployee e INNER JOIN tblManager m ON e.tbl_ID = m.tbl_ID WHERE NOT EXISTS(SELECT TOP 1 1 FROM tblEmployee e2 WHERE e2.E_ID = e.E_ID AND isFired = 'N' ) I suppose I haven't read/seen a layman's explanation yet that makes sense to me. Even after reading Diff between Top 1 1 and Select 1 in SQL Select Query I still don't get it
EXISTSNOT EXISTS, it's not necessary to useSELECT TOP 1there. A simpleSELECT *will use the clustered index and fast enough. One more thing, you could also checkEXISTS (SELECT 1/0 FROM A)and you will see1/0is actually not executed. So, usingTOPinEXISTSis really not a necessary.