Hi all,
I'm trying to improve the performance of a very slow running query. I'm linking master records to child or payment records via an intermediate table. Diagram:
For each master record there may be many entries (or 0) in the linking table and for each entry in the linking table there will be one child or payment record.
To get the most recent child or payment record for each master record I am using the following SQL. Can anyone thing of a more efficient way of doing this?
TIA
I'm trying to improve the performance of a very slow running query. I'm linking master records to child or payment records via an intermediate table. Diagram:
For each master record there may be many entries (or 0) in the linking table and for each entry in the linking table there will be one child or payment record.
To get the most recent child or payment record for each master record I am using the following SQL. Can anyone thing of a more efficient way of doing this?
Code:
select
rga.RecurringGiftID,
(
select top 1
p.RESystemId
from
dbo.WH_Gift p
where
p.RESystemID = rga.PaymentId
order by
p.date desc) LastPaymentID
from
RGA_Activity rga
TIA