I have a table of "encounters" with a unique ID and date, and a table of addendums which contain the same IDs and multiple update dates. Given a set of encounters that I specify, I need to know the last time it was updated.
My current query looks loosely like this:
SELECT
enc.encounter_id,
ISNULL(addend.date,enc.date) date
FROM
encounters enc
left outer join (select addendums.encounter_id,
max(addendums.update_date)
from addendums
group by addendums.encounter_id) addend on addend.encounter_id=enc.encounter_id
WHERE
*some criteria available on enc but not addend*
This functions as expected, but I'm concerned that I'm running the derived table addend for all lines. Does the plan pass the join criteria and only run the derived table for each encounter ID? Or is the derived table ran for all lines every time?