Something like
Code:
select
subf_id, post_id from
(select top 5
subf_id,
post_id,
max(datetime) as dt
from item
group by
subf_id,
post_id
order by dt desc) as list
Not sure if your db platform will support this kind of subquery, but it's worth a shot.