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)
 distinct value

Author  Topic 

kick_one
Starting Member

2 Posts

Posted - 2005-01-03 : 06:21:34
i have a table like:

a b c
-----------
1 280 a
1 290 b
1 210 c
2 190 d
2 199 e
3 190 f
3 160 g

and i want a query with results like:

a b c
----------
1 290 b
2 199 e
3 190 f


so i need distinct values from column a, and the max value from column b.

I've tried in differet ways, but no luck. Maybe someone can help me with an idea, how to start.


Thanks

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-01-03 : 06:40:26
this is using a derived table:
select table.a, table.b, table.c
from table
join (select a,max(b) as b from table group by a) maxb -- derived table
on table.a = maxb.a
and table.b = maxb.b


rockmoose
Go to Top of Page

kick_one
Starting Member

2 Posts

Posted - 2005-01-03 : 07:03:59
Thank you very much

I learned another thing :)

I hope to learn more things here.
Go to Top of Page
   

- Advertisement -