I have a table with columns
Index, Date
where an Index may have multiple Dates, and my goal is the following: select a list that looks like
Index, MinDate, MaxDate
where each Index is listed only once, and MinDate (MaxDate) represents the earliest (latest) date present in the entire table for that index. That's easy enough, but then let's constrain this list to appear only for Indexes that are present in a given range of dates.
So far, I have the following:
SELECT
Index,
MIN([Date]),
MAX([Date])
FROM myTable
WHERE
Index IN
(SELECT Index From myTable WHERE [Date] BETWEEN '1/1/2000' AND '12/31/2000')
GROUP BY Index
ORDER BY Index ASC
This is excruciatingly slow. Any way to speed this up? [I am running SQL Server 2000.]
Thanks!
Edited: For clarity.