Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Get TOP 1 record for each FName column

Author  Topic 

vinothrao84
Starting Member

21 Posts

Posted - 2007-10-08 : 23:02:07
Hi,

Below are my sample records in a SQL table.

FName ........ Points.......Date
Toyota ........150..........05/12/2005
Honda ........ 115 .........10/10/2003
Mitsubishi.....120..........06/06/2005
Toyota.........130..........01/01/2005
Honda .........135 .........11/07/2003
Mitsubishi ....110..........16/06/2005
Toyota ........160..........25/11/2005
Honda .........125..........12/12/2003
Mitsubishi.....110 .........26/02/2005

I want to get the result as below.

Toyota ........160
Honda .........135
Mitsubishi.....120

How can i get the TOP 1 records for each FName column?

Pls Help.

Thx.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-08 : 23:08:14
SELECT FName, MAX(Points) AS Points
FROM YourTable
GROUP BY FName

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-09 : 02:15:07
Tara, why do you get all the hard queries?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-09 : 03:44:54
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -