Home Forums SQL Server 2008 SQL Server Newbies SQL Query of last records(timestamp) for Distinct CategoryId's in same table. RE: SQL Query of last records(timestamp) for Distinct CategoryId's in same table.

  • This is what i used:

    SELECT

    MAX(ACTIVITIES.StartDateTime) as LastStartDateTime,

    ACTIVITIES.CategoryId

    FROM Activities

    GROUP BY ACTIVITIES.CategoryId

    This query gave me the 731 results i wanted, however i also need the Activity.Id

    I tried this but was unsuccessful:

    SELECT

    MAX(ACTIVITIES.StartDateTime) as LastStartDateTime,

    ACTIVITIES.CategoryId,

    ACTIVITIES.Id

    FROM Activities

    GROUP BY ACTIVITIES.CategoryId, ACTIVITIES.Id

    This query results in 69378 results.

    Am I still missing something here???