1

I don't think this is a duplicate. I want to return multiple records each having the max date for a given type. I can do this is several lines I am just wondering if it can be done in one?

so I have a table

int, DateTime, varchar, int
id,  date,     message, type
1,   2000-1-1, hello,   2
2,   2000-1-2, goodby,  1
3,   2000-1-1, again,   1

Is there a way to return to oldest record for each type? so that would be record id 2 and id 1

  • possible duplicate of [LINQ Using Max() to select a single row](http://stackoverflow.com/questions/9114863/linq-using-max-to-select-a-single-row) – Rawling May 22 '14 at 13:07

1 Answers1

1

You can group your data by type, then order each group by date and take the first item.

var result = yourTable.GroupBy(d => d.type)
                      .Select(g => g.OrderByDescending(x => x.date).First());
sloth
  • 99,095
  • 21
  • 171
  • 219