I have a table like below:
COL1 | COL2 | COL3
______________________
ITEM1 | CLASS1 | DATE1
ITEM2 | CLASS3 | DATE2
ITEM3 | CLASS1 | DATE3
ITEM4 | CLASS2 | DATE4
ITEM5 | CLASS1 | DATE2
ITEM6 | CLASS3 | DATE6
ITEM7 | CLASS2 | DATE3
.
.
I want to arrange the data by descending date and then get the top 2 entries for every class. I am unable to figure out how to do this. Please help.
Try this query, it ranks records in a group, then uses rank to filter result –