selecting top N rows for each group in a table
I am facing a very common issue regarding "Selecting top N rows for each group in a table". Consider a table with id, name, hair_colour, score columns. I want a resultset such that, for each hair colour, get me top 3 scorer names. To solve this i got exactly what i need on Rick Osborne's blogpost "sql-getting-top-n-rows-for-a-grouped-query" That solution doesn't work as expected when my scores are equal. In above example the result as follow. id name hair score ranknum --------------------------------- 12 Kit Blonde 10 1 9 Becca Blonde 9 2 8 Katie Blonde 8 3 3 Sarah Brunette 10 1 4 Deborah