I have 3 values that I need to copy from one table to another table. Here is my amateur attempt at it, I know it is horribly ineffecent, what would the correct way of doing this query?
update [IDAT_PATIENTS]
set TargetRabiesSerial =
(select top 1 SERIAL_NUMBER
from [IDAT_RABIESHISTORY] as rab
where TargetPetAccountNum = rab.PATIENT_ACCOUNT_ID
and TargetClientAccountNum = rab.CLIENT_ACCOUNT_ID
order by rab.DATE_TIME_PERFORMED desc)
, TargetRabiesBrandName =
(select top 1 BRAND_NAME
from [IDAT_RABIESHISTORY] as rab
where TargetPetAccountNum = rab.PATIENT_ACCOUNT_ID
and TargetClientAccountNum = rab.CLIENT_ACCOUNT_ID
order by rab.DATE_TIME_PERFORMED desc)
, TargetRabiesTag =
(select top 1 TAG_NUMBER
from [IDAT_RABIESHISTORY] as rab
where TargetPetAccountNum = rab.PATIENT_ACCOUNT_ID
and TargetClientAccountNum = rab.CLIENT_ACCOUNT_ID
order by rab.DATE_TIME_PERFORMED desc)
where TargetClientAccountNum in
(select CLIENT_ACCOUNT_ID
from [IDAT_RABIESHISTORY]
where TargetPetAccountNum = PATIENT_ACCOUNT_ID)