Selecting the maximum value from a denormalized table

  • I inherited a table with this structure:

    Value a Value b

    x date a

    x date b

    x date c

    y date d

    z date e

    z date e

    z date f

    Value a fields are one to many. The objective is to obtain the maximum date value for each unique a value.

    I am thinking a correlated sub query could do this, but I am feeling dumb today. Help please...

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • Does your table have two columns (value a, value b) or three columns (value a, date, value b)? If it's the latter, you could get max date for each value a with something like this.

    select [value a],max(date)

    from table

    group by [value a]

    Have a look at the link in my signature tips on how to post to make it easier for other to help you

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

  • Nice. I found a solution using a correlated sub-query but yours is simpler.

    Done.

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply