Sorry about the vague title but i couldn't found any suitable title her is a scenario:i have a expenses table and a categories table like that:Categories( CategoryId CategoryName)Expenses( ExpensesId Spends decimal CategoryId)
i want to select top two Spends for each Categoryif i had Id Spends CategoryId 1 20 1 2 10 1 3 60 1 4 90 2 5 10 2 6 16 2
this should returns Spends CategoryId 60 1 20 1 90 2 16 2
i also want to join the categories table to select the category namei tried something like the following you can modify it select cc.cn, cc.ss from( select c.Category_Name cn, e.Spends ss from Expenses e inner join Categories c on e.Category_Id = c.Category_Id group by e.Spends,c.Category_Name ) as cc order by cc.ss
thanks in advance