Is there an alternative to the correlated subquery. Running the subquery for each row returned by the outer query must be expensive.
Any help greatly appreciated.
Graham Robbins
The following is an example of a correlated subquery:
/*
Ensure that only the most recently added patient contact of each type is current per patient
*/
UPDATE tblAddressPatient
SET tblAddressPatient.Status = 'Obsolete'
WHERE tblAddressPatient.Id <> (
SELECT TOP 1 tblAP.Id
FROM tblAddressPatient AS tblAP
WHERE tblAP.CIN = tblAddressPatient.CIN
AND tblAP.AddressTypeID = tblAddressPatient.AddressTypeID
ORDER BY tblAP.Id DESC
)
Any help greatly appreciated.
Graham Robbins
The following is an example of a correlated subquery:
/*
Ensure that only the most recently added patient contact of each type is current per patient
*/
UPDATE tblAddressPatient
SET tblAddressPatient.Status = 'Obsolete'
WHERE tblAddressPatient.Id <> (
SELECT TOP 1 tblAP.Id
FROM tblAddressPatient AS tblAP
WHERE tblAP.CIN = tblAddressPatient.CIN
AND tblAP.AddressTypeID = tblAddressPatient.AddressTypeID
ORDER BY tblAP.Id DESC
)