Query to get last record change per account number


New Member
Hello Everyone,
I needed a little help!
What i wanted to achieve is that, from a table i have several data per account number, -i.e there are several date the data has changed, i wanted to get only the latest data per account number by its last date the account has been updated.

acc no on row 133 and 134 is the same, but date prop has been changed, i want to get only the data for the last record only for each account number.

Here is my actual query used.

SELECT distinct e.acctno
        , r.[custid]
        , c.title

    FROM cosacs.dbo.customer as c
        ,[cosacs].[dbo].[referral] as r
        ,cosacs.dbo.custacct as e
        ,cosacs.dbo.acct as a

    where  e.custid = r.custid
        and c.custid = r.custid
        and e.acctno = a.acctno
        and a.accttype != 'C'
        and a.accttype != 'S'

  ORDER BY r.[dateprop] DESC
Last edited: