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)
 Help for Query

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2008-02-25 : 03:32:46
Hi there

I am try to get the top for each group:

Field1 | Field2 | Field3 | Field4
1 | 200 | TEST | TEST1
1 | 400 | TEST2 | TEST4
2 | 300 | TEST | TEST3
2 | 600 | TEST3 | TEST10

The result will be:

Field1 | Field2 | Field3 | Field4
1 | 400 | TEST2 | TEST4
2 | 600 | TEST3 | TEST10

Field1 is ID while Field2 is numeric.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-25 : 03:53:05
[code]SELECT t1.*
FROM Table t1
INNER JOIN (SELECT Field1,MAX(Field2) AS Field2
FROM Table
GROUP BY Field1) t2
ON t1.Field1=t2.Field1
AND t1.Field2=t2.Field2[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-25 : 04:07:41
select t1.* from table1 AS t1
inner join (
SELECT field1, MAX(Field2) AS f2 FROM Table1 group by field1
) as x on x.field1 = t1.field1
where t1.field2 = x.f2



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

- Advertisement -