Fetch Max from a date column grouped by a particular field

Posted by vamyip on Stack Overflow See other posts from Stack Overflow or by vamyip
Published on 2011-01-17T13:51:05Z Indexed on 2011/01/17 13:53 UTC
Read the original article Hit count: 211

Filed under:
|
|

Hi,

I have a table similar to this:

LogId  RefId   Entered
==================================
1      1       2010-12-01
2      1       2010-12-04
3      2       2010-12-01
4      2       2010-12-06
5      3       2010-12-01
6      1       2010-12-10
7      3       2010-12-05
8      4       2010-12-01

Here, LogId is unique; For each RefId, there are multiple entries with timestamp. What I want to extract is LogId for each latest RefId.

I tried solutions from this link:http://stackoverflow.com/questions/121387/sql-fetch-the-row-which-has-the-max-value-for-a-column. But, it returns multiple rows with same RefId.

Can someone help me with this?

Thanks

Vamyip

© Stack Overflow or respective owner

Related posts about sql

Related posts about aggregate-functions