Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    9

    Unanswered: Returning the newest occurences

    I am trying to return the newest occurences from a dataset. For simplicty sake:

    I have a dataset that has three fields in it 1)Name, 2)EntryDate, and 3)Description.

    I'd like to return all three columns, but only the row with the last entry date for each Name.

    My first attempt was:

    Select EntryDate, Name, Description
    From TestTable
    Group by Name, EntryDate
    Order by Name, Max(EntryDate)

    I get an error message that Description is invalid in the select list because it is not contained in either an aggregate function or the group by clause.

    Does anyone have any suggestions?
    Last edited by Salthead; 09-22-08 at 17:19.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Code:
    SELECT T2.[name],T2.Description,T2.Entrydate
    FROM TestTable T2
    JOIN
    	(Select MAX(EntryDate) as entrydate, [Name]
    	From TestTable
    	Group by [Name]) T1
    ON T2.[name] = T1.[name]
    AND T2.entrydate = T1.entrydate
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Apr 2004
    Posts
    9
    Thanks!! It did the job nicely.

Posting Permissions

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