Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select top n rows for each value 1

Status
Not open for further replies.

onwagena

Technical User
Jan 11, 2004
8
NL
I have a table looking like this:

Verr Date
1 1-9-2006
1 2-9-2006
1 3-9-2006
2 5-9-2006
2 6-9-2006
3 2-9-2006
4 1-9-2006
4 5-9-2006
4 7-9-2006
4 9-9-2006

I would like to see the latest 2 dates of every Verr. The result must look like

Verr Date
1 2-9-2006
1 3-9-2006
2 5-9-2006
2 6-9-2006
3 2-9-2006
4 7-9-2006
4 9-9-2006

Who knows a solution to this problem?
 
Try this

select verr,date from
(
select verr,date,dense_rank() over(partition by verr order by verr,date desc) rnk
from your_table) t1
where t1.rnk <=2
 
Thanks,

This is wat I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top