Say I have the following data
Name Value
===============
Small 10
Medium 100
Large 1000
Imagine that these represent the
SELECT *
FROM (
SELECT *
FROM (
SELECT *
FROM mytable
WHERE value > 10000
ORDER BY
value
)
UNION ALL
SELECT *
FROM (
SELECT *
FROM mytable
ORDER BY
value DESC
)
)
WHERE rownum = 1
This will both efficiently use an index on mytable(value)
and COUNT(STOPKEY)
.
See this article in my blog for performance details: