Do you care which ID and which RsvTime you get back? You could group by the other columns and take the min or max of ID and RsvTime if you don't mind them possibly being from different rows. or you could use cross apply to get the value from the same row:SELECT max(ID) as ID ,max(RsvTime) as RsvTime ,RsvNumber ,price ,ammount ,spCodeTTfrom <yourTable>group by RsvNumber ,price ,ammount ,spCodeTTSELECT max(ca.ID) as ID ,max(ca.RsvTime) as RsvTime ,t.RsvNumber ,t.price ,t.ammount ,t.spCodeTTfrom <yourTable> tcross apply ( select top 1 ID, RsvTime from <yourTable> where RsvNumber = t.rsvNumber and price = t.price and amount = t.amount and spCodeTT = t.spCodeTT order by ID desc ) cagroup by t.RsvNumber ,t.price ,t.ammount ,t.spCodeTT
Be One with the OptimizerTG