Hello,
I have a table (PAT_PROCEDURES) with three columns: patient_id, procedure_id, procedure_date, and token_id that stores records about patients and procedures they've undergone as well as the procedure's date; token ID is a special numeric identifier.
I also have another table (PAT_TOKENS) with three columns patient_id and token_id, it has a subset of those patients from the first table, but the token ID is 0. I'm trying to update the token ID to be that of the most recent procedure performed from the first table, where the procedures is one of a finite list of procedure IDS....basically here's what I have so far:
merge into pat_tokens t
using (
-- select all patients with most recent procedure among procedure IDs (45, 66, 78)
) procs on (t.patient_id = procs.patient_id)
when matched then
update set t.token_id = procs.token_id
The commented select query is what i'm struggling with.
THanks!