Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a query which selects a max value over all the values of in a datetime column (dtimesent).

select dtimesent, max(ResponseTime) AS maxtime
FROM allrequests 
where Request like '%Requestsa%'
group by dtimesent

I need to get the value of the request colmn for each max response time in each group by. Is there any easy way to do this? There can be multiple rows per dtimesent value so I can't just include the request column in the group by,

Many thanks,

share|improve this question

1 Answer 1

RANK will deal with multiple max values (instead of ROW_NUMBER)

   dtimesent, Request, ResponseTime
    select dtimesent, Request, ResponseTime ,
       RANK() OVER (ORDER BY ResponseTime DESC) AS rn
    FROM allrequests 
    where Request like '%Requestsa%'
    ) T
   rn = 1

Also see How to get the MAX row please

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.