On 04/14/2012 03:14 AM, Steinar Midtskogen wrote:
Puneet Kishor<punk.k...@gmail.com> writes:
If you want the results in separate columns, you can do something like
SELECT Min(a) minimum, 'none' maximum FROM t UNION ALL SELECT 'none' minimum,
Max(a) minimum FROM t;
Then it does a full scan again.
But Igor's suggestion "SELECT (SELECT min(unix_time) FROM table),
(SELECT max(unix_time) FROM table)" works fine, and means less code.
This:
http://www.sqlite.org/optoverview.html#minmax
Both the subqueries qualify for the optimization, so the overall
query is fast. With the UNION ALL version, the second column in the
result set disqualifies both sides from using the optimization. So
it is slow.
I think if you were to change the UNION ALL version to the following
it would be just as fast as the sub-selects.
SELECT Min(a) minimum FROM t
UNION ALL
SELECT Max(a) minimum FROM t;
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users