Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retrieve top rows from a number of groups?

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
0
0
HK
Hello everybody, I have a SQL question that i may want you professionals to do me a favour, thanks!

Suppose I have a table (no primary key) with rows like that:

ID COMMENT
-----------------------------
1 how are you?
1 how do you do?
1 I am fine
2 good morning
3 good evening
3 good night

Ok, I want to get the result that first has distinct groups
of ID, and then get the top row from the groups whose data in COMMENT may be ordered alphabetically. The result is like the below:

ID COMMENT
-------------------------------
1 how are you?
2 good morning
3 good evening


I am still green in SQL statement. I will be happy if some of you may help me :)
 
Select [ID], max([COMMENT]) from MyTable Group By [ID] Vlad Grynchyshyn, MVP
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top