Selecting Latest Records

  • I have a table  which contains serveral lists.  Each list has multiple records which were generated at different times.  There is a date stamp on each record.  I need to be able to select the group of records for each list which was generated at the latest date.

    Please hlep.

  • This should return a list of 'other' by listname and latest date.

    create table #myLists

    (id int identity, other varchar(20), listName varchar(20), insertDate datetime)

    select listName, other, insertDate

    from #myLists ml

    INNER JOIN

    (select listName, max(insertDate) mxdate FROM #myLists) as dl

    ON ml.listName = dl.listName and ml.insertDate = dl.mxDate

  • Thanks very much Daryl.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply