select gmt from history.cachemap order by gmt asc limit 0,1;
..this returns gmt: 2012-05-03
select gmt from history.cachemap order by gmt desc limit 0,1;
..this returns gmt: 2012-09-15
A little background on the database I’m working with, I’m trying to get the earliest and latest date fields from a list of several million records.
Earlier this week I posted this question:
How to combine three MySQL queries into one?
This question was answered perfectly, but doesn’t apply to this type of query.
I think the best way is to use the max and min functions. You can get the results as one row:
This is the most efficient solution, since it involves only one pass through the data.
Alternatively, you can put this into two rows, using union all:
UNION/UNION ALL does not return rows in a specified order, so you should include information on which is which (or order them explicitly).