I like to get the Max Sample Num for where the Id is 9
var samplecount = dbContext.ChemDetails
.GroupBy(a => a.Id == 9)
.Select(a => a.Max(w => w.Sample_Num))
.FirstOrDefault();
What I am getting from above is the max, not from where Id == 9.
You just need a
Whereclause, then take the max:If you wanted to get the max value for each
Id, that’s when you’d useGroupBy.