Hi,
Given the following table format...
id | date | value
___|____________|______
11 | 2010-01-01 | 50
11 | 2010-01-02 | 100
12 | 2010-01-01 | 150
12 | 2010-01-02 | 200
... I need to select the id
that corresponds to the maximum value
on a day that I specify. The only way I've figured out how to do this so far is using a sub-query as follows:
SELECT id
FROM table
WHERE date = '2010-01-01'
AND value = (
SELECT MAX(value)
FROM table
WHERE date = '2010-01-01'
GROUP BY date
)
On a table with ~70,000 records, with a primary key over id
and date
, this takes ~0.25 seconds to execute, which seems a long time to me. Is there a faster way for me to achieve the same result?
Thanks.