Your SQL is retrieving the high for each record in TestTable.
HOW many records do you have? Do you have an index on the Date field? The
query will take a long time with many records because it is running the query
in the where clause ONCE for every record in the table.
If you have a lot of records you may have to use two queries to get the
results you want. If you didn't have a field name Date that requires square
brackets to be used, you could do this all with a subquery in the from clause.
First Query (Save this as qMaxHigh)
SELECT [TestTable].[Date]
, Max([TestTable].[High]) as TheHigh
FROM [TestTable]
GROUP BY [TestTable].[Date]
Now you can use that saved query and your original table.
SELECT [TestTable].[Date]
, [TestTable].[Time]
, [TestTable].[High]
FROM [TestTable] INNER JOIN qMaxHigh
ON [TestTable].[Date] = qMaxHigh.[Date]
AND [TestTable].[High] = qMaxHigh.TheHigh
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Original code would hang but I finally got this to work:
SELECT [Date], [Time], [High]
FROM [TestTable]
WHERE [High] =
(SELECT Max([TestTable].High)
FROM [TestTable] AS T
WHERE T.[Date]=[TestTable].Date);
Some sample raw data (Date,Time,Open,High,Low,Close,Volume):
20090102;16:03:00;3694;3706;3694;3702;44
20090102;16:04:00;3700;3702;3697;3700;85
20090102;16:05:00;3699;3702;3698;3700;22
20090102;16:06:00;3699;3699;3697;3699;26
20090102;16:07:00;3700;3702;3700;3702;10
20090102;16:08:00;3704;3708;3704;3708;14
20090102;16:09:00;3707;3715;3707;3710;48
20090102;16:10:00;3709;3715;3705;3708;86
20090102;16:11:00;3706;3706;3696;3703;207
John W. Vinson said:
Many thanks, John. I managed to get this working, and I feel closer to the
answer, but alas it returns the Max(High) for every minute in the database,
not the highest High for the day. I'm after the highest High in every 24-hour
period and the Time (minute) that occurred. Apologies for not explaining it
properly (see my reply to Karl Dewey for further clarification).
Then you either didn't follow John Spencer's advice, or your table is not as
you described it: his subqueries will in fact retrieve the high and the low
for the day.
Please post the exact SQL of the query that you are using, and perhaps a few
rows of example data.
.