Re: How to select all top 1s from different group in a view



A pattern for this, assuming no NULLs in your columns, is

select
 Contract_KEY, Step
from yourTable as T1
where not exists (
 select * from yourTable as T2
 where T2.Contract_KEY = T1.Contract_KEY
 and T2.Step < T1.Step
)

Steve Kass
Drew University

adam wrote:

Hi SQL Query Guru,

I have a view like this:

Contract_KEY   Step
1                       1
1                       3
2                       1
2                       5
2                       4

How do I write a query to retrieve the following result:
1                       3
2                       5

Thanks very much!

-adams


.