• That's why we ask for the table schema.

    Assuming that the relationship between product_id and product_name is a 1-to-1, this should work

    SELECT table.uniquekey, table.product_id, table.product_name, sub.last_purchase_date

    FROM table INNER JOIN

    (Select

    product_id,

    Max(purchase_date) as last_purchase_date

    From

    table

    Group By

    product_id) sub on table.product_id = sub.product_id AND table.purchase_date = sub.last_purchase_date

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass