tags:

views:

42

answers:

2

I have a table Project. It has the following column:
Project ID, projectName, UpdateTime

The data in the table is as follows:

  Project ID   projectName   UpdateTime
       1          abc        12-2-2009 01:10:00
       1          abc        12-2-2009 04:18:00
       2          xyz        17-7-2009 08:45:00
       2          xyz        17-7-2009 12:21:00

i want the result set to display the latest update project information based on the update time.
for the above example , it should display

  Project ID   projectName   UpdateTime
       2          xyz        17-7-2009 12:21:00
       1          abc        12-2-2009 04:18:00
+1  A: 

This ought to do the job (as edited to reflect the information @Remou pointed out that I failed to note in your original question):

  SELECT [Project ID], ProjectName, Max(UpdateTime)
  FROM Project
  GROUP BY [Project ID], ProjectName
  ORDER BY Max(UpdateTime) DESC

If that doesn't do it, either I've made a mistake, or there's other information not included in your question.

David-W-Fenton
The fields (columns) are described as: Project ID, projectName, UpdateTime, so:SELECT [Project ID], projectName, Max(UpdateTime)To get the order specified, I believe ORDER BY Max(UpdateTime) is required.
Remou
I've altered my original answer to reflect that. Hint to new SO posters: formatting your data as code or with <PRE> tags is going to help the people reading your question give better answers.
David-W-Fenton
A: 
SELECT P.[Project ID]
     , P.projectName
     , Max(P.UpdateTime) AS [Latest Update Time]
FROM Project AS P
GROUP BY P.[Project ID]
     , P.projectName
ORDER BY Max(P.UpdateTime) DESC;
Jeff O