Now I came across an issue, I have table as below:
Task Id StudentId Marks
1 1 12
1 2 15
1 3 17
2 1 15
2 3 20
3 1 8
3 3 5
3 5 17
I was required to get a lists of studentid who has max and marks in each task. So the required output is:
TaskId StudentId Marks
1 3 17
2 3 20
3 5 17
Now I created a temporary table to store max.marks of each task.
TaskId Max.Marks
1 17
2 20
3 17
Then I joined the temporary table to the main table and fetched the row with marks equal to max.marks of that task.
Can anyone suggest a better query without any sub-queries and temporary table?
Thanks