I need to get a record of value and timestamp by the max of timestamp. The combination of value and timestamp is a primary key. It seems that there are two ways to get max/min value. One query example is by using TOP 1 + ORDER BY:
SELECT TOP 1
value, timestamp
FROM myTable
WHERE value = @value
ORDER BY timestamp DESC
Another one is by MAX() + GROUP BY:
SELECT value, max(timestamp)
FROM myTable
WHERE value = @value
GROUP BY value
Is the second one is better than the first one in terms of performance? I read one person's comment of "to sort n items by first one is O(n power of 2), second O(n)" to my previous question. How about the case I have index on both value and timestamp?