Saturday, February 10, 2007

Finding the latest / max records
I've just came up with aniother problem of getting a set of results. Finding the latest records, Example:
IDMobilenocreated
1+9099001-FEB-06
2+9099002-FEB-06
3+9099102-FEB-06
4+9099101-FEB-06

The results must be like this , only 1 mobileno with the latest creation date
IDMobilenocreated
2+9099002-FEB-06
3+9099102-FEB-06

The answer:
select t.*
from (select a.*,dense_rank() over (partition by mobileno order by created desc) dr from my_table a) t
where dr=1;

No comments: