I was reading (and am still learning) about the difference between the EXISTS and IN operators in SQL. Is it possible to change the following statement so it uses an EXISTS rather than IN? I’ve tried but the query is taking a very long time to complete. So I’m obviously doing something wrong.
In the below example would it be more efficient to use EXISTS instead of IN? There would be no more than 10 OperationRecordID records returned from the current sub-query used for the IN statement.
SELECT SPAS.SessionRecordID,
( SELECT MIN(TimeValue) AS MinAnaes
FROM tblTMActualTimes TMAT
WHERE OperationRecordID IN
( SELECT OperationRecordID
FROM tblTMActualOperation TMAO
WHERE TMAO.SessionRecordID = SPAS.SessionRecordID
)
AND CFTimeDefinitionID = 'INTOANS'
) AS FirstAnaesthetic
FROM tblSPActualSession SPAS
As said in the comments it depends on the data what is more suitable for the situation. But if you what to do it in an exist you can do it something like this: