I have a solution, however I'm not sure at all it is the simplest approach:
List<Item> items=new List<Item>();
items.Add(new Item("john","april",12));
items.Add(new Item("john", "june", 9));
items.Add(new Item("john","may",12));
items.Add(new Item("mary","may",3));
items.Add(new Item("mary","august",5));
items.Add(new Item("bob","may",25));
var someItems = items.Where(x => x.Score == items.Where(z => z.Name == x.Name)
.OrderByDescending(y => y.Score)
.First().Score);
foreach (var item in someItems) {
Console.WriteLine(item.ToString());
}
with
public class Item {
public string Name;
public string Month;
public int Score;
public Item(string name, string month, int score) {
this.Name = name;
this.Month = month;
this.Score = score;
}
public override string ToString() {
return Name + "," + Month + ","+Score;
}
}
ADDED:
Order-then-first makes no sense, better is:
var someItems = items.Where(x => x.Score == items.Where(z => z.Name == x.Name)
.Max(y => y.Score));
ADDED2: I am aware this isn't SQL; however you can use LINQ on databases or you can apply the same approach yourself in SQL (Two nested SELECT statements).
ADDED3:
mysql - SQL select only rows with max value on a column - Stack Overflow[
^] shows you two ways to do it in SQL.