Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Unanswered: Need solution - query to fetch latest record

    Hi All,

    Need your help in finding the solution for the below requirement:

    Table has details like below:

    NAME UPATE-TIMESTAMP
    ==== ===============
    mary time1
    mary time2
    mary time3
    tom time1
    tom time2
    tom time3
    tom time4
    richard time1
    richard time2

    Output Expected:

    NAME UPATE-TIMESTAMP
    ==== ===============
    mary time3
    tom time4
    richard time2

    In summary, the requirement is to fetch the latest upated record for each unique NAME.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Huh. The guy in the thread next door had a very similar question. Try this
    Code:
    with CTE
    as
    (select row_number() over (partition by name order by [update-timestamp] desc) place, name, [update-timestamp]
    from tablename goes here)
    select *
    from CTE
    where place = 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •