none
select min value from each group RRS feed

  • Question

  • I have a table like this:
    Num DateValue
    1 1/2/2010
    1 2/4/2009
    1 5/13/2008
    1 1/13/2011
    2 2/23/2007
    2 7/8/2002
    2 12/17/2005
    3 6/9/2003
    3 7/1/2010
    4 5/10/2008
    4 7/26/2009
    4 1/18/2011

    I want to get the min date for each Num group

    Num DateValue
    1 5/13/2008
    2 7/8/2002
    3 6/9/2003
    4 5/10/2008

    How would I do this in LINQ?

    Wednesday, March 2, 2011 8:30 PM

Answers

  • I solve this by doing this, is there a better way?

    from t in table

    group t.DateValue by t.Num into g

    select new

    {

    g.Key,

    Min = g.Min( x=>x)

    }

    Wednesday, March 2, 2011 8:56 PM

All replies