Query to get last record change per account number

Far

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.
E.g
upload_2017-7-13_11-6-47.png


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.

Code:
SELECT distinct e.acctno
        , r.[custid]
        , c.title
        ,c.firstname
        ,c.name
        ,r.[empeeno]
        ,r.[dateprop]
        ,r.[reflresult]
        ,r.[datereferral]

    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:
Top